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

Cyclomatic complexity updates and fixes #3495

Merged

Conversation

MarkBaker
Copy link
Contributor

@MarkBaker MarkBaker commented Dec 3, 2021

Resolve 3 issues with the Cyclometric Complexity sniff

  • Fix for Issue #3468
    do/while loops are double-counted in the Generic.Metrics.CyclomaticComplexity sniff
  • Fix for Issue #3469
    Ternary Operator and Null Coalescing Operator are not counted in the Generic.Metrics.CyclomaticComplexity sniff
  • Issue #3472
    PHP 8 match() expression is not counted in the Generic.Metrics.CyclomaticComplexity sniff

This PR replaces PR #3470, PR #3471 and PR #3473

MarkBaker added 3 commits December 3, 2021 15:49
…le loop

This is a bugfix for Issue squizlabs#3468, which identified that the count was being incremented twice when calculating the score because the sniff was checking for both the T_DO and the terminating T_WHILE tokens, incrementing CYC by two (once for each token) in the do/while loop, rather than just by one (as it should).

Code in the unit test .inc file has ben modified to reflect this change, and the test php file has also been modified to reflect the change in error line numbers.
…into CyclomaticComplexity calculation

This is for Issue squizlabs#3469, which identified that these operators were not being included in the count, when they should have been (treated as an if/else condition).

Unit tests provided.
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
Copy link
Member

Thanks a lot for these fixes, and thanks for merging those three PRs and sorting out the test file changes. This will be released in version 3.6.2.

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

Successfully merging this pull request may close these issues.

None yet

2 participants