This repository was archived by the owner on Aug 27, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 27, 2026. It is now read-only.
Cleanup Tokenizer #3
Copy link
Copy link
Open
Description
mhsdesign
opened on Nov 10, 2022
Issue body actions
No description provided.
Reactions are currently unavailable
Activity
1
i dislike those three methods:
they are hard to make sense out of...PackageFactory.ComponentEngine/src/Parser/Tokenizer/TokenType.php
Lines 138 to 158 in f58db0a
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
At first i didnt even understand whatclosingBracketwas doing, i though it would returnself::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
put them inline or sth. They do feel like an anomaly ...PackageFactory.ComponentEngine/src/Parser/Tokenizer/Tokenizer.php
Lines 56 to 71 in 62965ec
$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)) {
Metadata
Metadata
Assignees
Labels
No labels