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

Extract token array shape into a Psalm type #64

Merged
merged 1 commit into from
Feb 28, 2022

Conversation

greg0ire
Copy link
Member

This should make things less error prone and easier on the eyes.

@@ -160,7 +162,7 @@ public function isNextToken($token)
/**
* Checks whether any of the given tokens matches the current lookahead.
*
* @param string[] $tokens
* @param list<int|string|null> $tokens
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know if it makes sense to allow null here, but I'm forced to do so if a token type can be passed here. Either this is correct or there should be a subtype of Token that disallows null. Maybe we should also rename $tokens to $tokenTypes to make things less confusing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looking a bit more into the code, I think the type will be null if it is not understood by the lexer (no condition in getType matches the value). I don't think it makes sense to check if that's the case, so let me create another type just for that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe we should also rename $tokens to $tokenTypes to make things less confusing.

skipUntil uses $type, so let's be consistent with that.

@greg0ire greg0ire force-pushed the token-type branch 2 times, most recently from 76f3e06 to 50de489 Compare February 27, 2022 15:30
This should make things less error prone and easier on the eyes.
@greg0ire greg0ire added the bug label Feb 28, 2022
@greg0ire greg0ire added this to the 1.2.3 milestone Feb 28, 2022
@greg0ire greg0ire merged commit c268e88 into doctrine:1.2.x Feb 28, 2022
@greg0ire greg0ire deleted the token-type branch February 28, 2022 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants