-
-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TASK] Use proper docblock type for AbstractLexer::isNextTokenAny()
#63
Conversation
You can use |
} | ||
|
||
/** | ||
* @psalm-return list<array{string, list<array{value: string|int, type: string, position: int}>}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @psalm-return list<array{string, list<array{value: string|int, type: string, position: int}>}> | |
* @psalm-return list<array{string, list<array{value: string|int, type: string|int, position: int}>}> |
While reading your PR, I noticed there are a lot of repetition of the array shape describing a token. I attempted to extract it into a Psalm type in #64, and was forced by static analysis to apply the main change you did to this PR, as well as some others. Please review it.
I'll do a release as soon as we merge either your PR or mine. |
@@ -160,7 +160,7 @@ public function isNextToken($token) | |||
/** | |||
* Checks whether any of the given tokens matches the current lookahead. | |||
* | |||
* @param string[] $tokens | |||
* @param list<int|string> $tokens |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should skipUntil
be changed as well?
This change adds a test lexer with integer based tokens, which is a valid lexer implementation, at least as this is provided as a simple lexer implementation in the docs. See: https://www.doctrine-project.org/projects/doctrine-lexer/en/1.2/simple-parser-example.html#simple-parser-example
This patch changes the docblock type hint of `AbstractLexer::isNextTokenAny()` to `list<int|string>` to adopt the int and string based support of token types. Thus making phpstan in projects happy which uses this packages for there own lexer implementations. However this only aligns to other token methods which already supports int and string as token types, thus fixing a wrong set type hint through doctrine#48. Fixes: doctrine#62
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but I think we should wait for #64 first, if it is merged then this should be rebased and reworked to use a Psalm type in the new test you introduced IMO. If not, let's merge as is.
Please address the conflicts, and use a Psalm type. |
[TASK] Use proper docblock type for
AbstractLexer::isNextTokenAny()
This patch changes the docblock type hint of
AbstractLexer::isNextTokenAny()
to
list<int|string>
to adopt the int and string based support of token types.Thus making phpstan in projects happy which uses this packages for there own
lexer implementations.
However this only aligns to other token methods which already supports int and
string as token types, thus fixing a wrong set type hint through #48.
Additionally a concrete lexer implementation was added to test a lexer implemention
with integer based tokens, adopted from the already string based implementation.
If this got accepted and merged, it would be nice to have a patchlevel release in
the nearer time.
Fixes: #62