This repository was archived by the owner on Aug 27, 2026. It is now read-only.
This repository was archived by the owner on Aug 27, 2026. It is now read-only.
Activity
mhsdesign commented on Nov 10, 2022
ContributorAuthor
More actions
1
i dislike those three methods:
|
public static function tryBracketOpenFromFragment(Fragment $fragment): ?self |
|
{ |
|
return match ($fragment->value) { |
|
'{' => self::BRACKET_CURLY_OPEN, |
|
'(' => self::BRACKET_ROUND_OPEN, |
|
'[' => self::BRACKET_SQUARE_OPEN, |
|
default => null |
|
}; |
|
} |
|
|
|
public function closingBracket(): TokenType |
|
{ |
|
return match ($this) { |
|
self::BRACKET_CURLY_OPEN => self::BRACKET_CURLY_CLOSE, |
|
self::BRACKET_ROUND_OPEN => self::BRACKET_ROUND_CLOSE, |
|
self::BRACKET_SQUARE_OPEN => self::BRACKET_SQUARE_CLOSE, |
|
default => throw new \Exception('@TODO: Not a bracket.') |
|
}; |
|
} |
|
|
|
public function matchesString(string $string): bool |
they are hard to make sense out of...
At first i didnt even understand what
closingBracket was doing, i though it would return
self::BRACKET_CURLY_OPEN => self::BRACKET_CURLY_OPEN, but it gives the closing bracket for the opening bracket - my eyes didnt catch that.
so my take would be to have better method naming, or as those methods are only called at one place - inside
|
$bracket = TokenType::tryBracketOpenFromFragment($fragments->current()); |
|
$buffer = Buffer::empty(); |
|
|
|
if ($bracket) { |
|
yield from $buffer->append($fragments->current())->flush($bracket); |
|
$fragments->next(); |
|
} |
|
|
|
while ($fragments->valid()) { |
|
/** @var Fragment $fragment */ |
|
$fragment = $fragments->current(); |
|
|
|
if ($bracket) { |
|
$closingBracket = $bracket->closingBracket(); |
|
|
|
if ($closingBracket->matchesString($fragment->value)) { |
put them inline or sth. They do feel like an anomaly ...
Metadata
Metadata
Development
No branches or pull requestsIssue actions