Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

sbuerk
Copy link

@sbuerk sbuerk commented Feb 27, 2022

[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

@greg0ire
Copy link
Member

You can use git rebase -i HEAD^^ --exec vendor/bin/phpcbf to fix the coding standard issues.

}

/**
* @psalm-return list<array{string, list<array{value: string|int, type: string, position: int}>}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @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}>}>

@greg0ire
Copy link
Member

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.

If this got accepted and merged, it would be nice to have a patchlevel release in
the nearer time.

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
Copy link
Member

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
Copy link
Member

@greg0ire greg0ire left a 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.

@greg0ire
Copy link
Member

Please address the conflicts, and use a Psalm type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Changed DocBlock param type invalid or not consistent
2 participants