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

PHP 8 match() expression is not counted in Generic.Metrics.CyclomaticComplexity #3472

Closed
MarkBaker opened this issue Nov 11, 2021 · 0 comments

Comments

@MarkBaker
Copy link
Contributor

PHP8 Introduced match() as a new expression syntax, similar to a switch statement but with a rather different structure, using an arrow (=>) to separate the case from the expression that it would return. This should also be factored into the CYC calculation for the Generic.Metrics.CyclomaticComplexity sniff.

When calculating the CYC, this should be evaluated like a switch statement, with each T_MATCH_ARROW token corresponding to a case and increasing the CYC by one. There is no need to add one for the T_MATCH_DEFAULT token, because this is followed by a T_MATCH_ARROW token, and to do so would be to double-count that entry.

PR to follow.

MarkBaker pushed a commit to MarkBaker/PHP_CodeSniffer that referenced this issue Nov 12, 2021
Calculate CYC for PHP 8 match() expression in Cyclomatic Complexity sniff
@MarkBaker MarkBaker changed the title PHP 8 match is not counted in the Generic.Metrics.CyclomaticComplexity sniff PHP 8 match() expression is not counted in the Generic.Metrics.CyclomaticComplexity sniff Nov 12, 2021
@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Dec 3, 2021
@gsherwood gsherwood added this to the 3.6.2 milestone Dec 3, 2021
MarkBaker pushed a commit to MarkBaker/PHP_CodeSniffer that referenced this issue Dec 3, 2021
This is for Issue squizlabs#3472, which identified that match() was not being included in the count, when it should have been (similar to a switch statement).
There is no need to add one for the T_MATCH_DEFAULT token, because this is always followed by a T_MATCH_ARROW token, and to do so would be to double-count that entry.

Unit tests provided.
@gsherwood gsherwood changed the title PHP 8 match() expression is not counted in the Generic.Metrics.CyclomaticComplexity sniff PHP 8 match() expression is not counted in Generic.Metrics.CyclomaticComplexity Dec 6, 2021
gsherwood pushed a commit that referenced this issue Dec 6, 2021
This is for Issue #3472, which identified that match() was not being included in the count, when it should have been (similar to a switch statement).
There is no need to add one for the T_MATCH_DEFAULT token, because this is always followed by a T_MATCH_ARROW token, and to do so would be to double-count that entry.

Unit tests provided.
PHPCS v3 Development automation moved this from Idea Bank to Ready for Release Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
PHPCS v3 Development
Ready for Release
Development

No branches or pull requests

2 participants