-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
No support for namespace operator used in type declarations #3066
No support for namespace operator used in type declarations #3066
Conversation
632ba23
to
1faa467
Compare
@jrfnl I've marked this for the 3.5.7 release but I'd appreciate it if you could give me a second opinion on the risk. I'm wondering if this is better included in 3.6.0. |
@gsherwood I don't see much risk here as this is a straight bug fix: valid PHP not being tokenized correctly in PHPCS. Running the unit tests of various external standards with this branch is successful, but as this syntax was so far basically unsupported by PHPCS, that's not really surprising as they probably don't have any tests in place covering this syntax. All the same, if you deem it risky, I'm fine with it being marked for PHPCS 3.6.0. As for the impact:
Future scope, building on top of this change:
Note: the changes mentioned in the "Future scope" would only be relevant for PHPCS 3.x as PHPCS 4.x will use different tokens - per #3041 -, which is why I haven't made those changes. |
The `namespace` keyword as an operator is perfectly valid to be used as part of a type declaration. This usage was so far not supported in the tokenizer for the determination whether a `?` is a nullable type token or a ternary. Fixed now.
…tions The `namespace` keyword as an operator is perfectly valid to be used as part of a type declaration. This usage was so far not supported in the tokenizer for the arrow function backfill. Fixed now.
…mespace relative type declarations The `namespace` keyword as an operator is perfectly valid to be used as part of a type declaration. This usage was so far not supported in the `File::getMethodParameters()`, `File::getMethodProperties()` and the `File::getMemberProperties()` methods. Fixes now. Including adding a unit test for each.
1faa467
to
16d2cd1
Compare
The namespace keyword as a scope opener can never be within another scope, so we can safely ignore it when encountered as it will always be the namespace keyword used as an operator in that case. Includes dedicated unit tests.
Rebased for merge conflicts. |
I didn't know that was allowed - thanks for finding and fixing it. Have picked this into the 4.0 branch as well. |
Thanks. |
Follow up on #3063 (comment)
The
namespace
keyword as an operator is perfectly valid to be used as part of a type declaration.See: https://3v4l.org/hvjlL
This usage was so far not supported in the tokenizer for the determination whether a
?
is a nullable type token or a ternary, nor was it taken into account for skipping over the return type for an arrow function in the backfill.Lastly, this usage was so far not supported in the
File::getMethodParameters()
,File::getMethodProperties()
and theFile::getMemberProperties()
methods.Fixed now.
Includes select unit tests covering the functionality.
[Edit]
I've added an additional commit fixing the
Tokenizer::recurseScopeMap()
method as when the namespace keyword used as an operator was encountered, the scope openers/closers would incorrectly not be set.The namespace keyword as a scope opener can never be within another scope, so we can safely ignore it when encountered as it will always be the namespace keyword used as an operator in that case.
Includes dedicated unit tests.