You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
MarkBaker
pushed a commit
to MarkBaker/PHP_CodeSniffer
that referenced
this issue
Nov 12, 2021
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
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
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
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.
PHP8 Introduced
match()
as a new expression syntax, similar to aswitch
statement but with a rather different structure, using an arrow (=>
) to separate thecase
from the expression that it would return. This should also be factored into the CYC calculation for theGeneric.Metrics.CyclomaticComplexity
sniff.When calculating the CYC, this should be evaluated like a
switch
statement, with eachT_MATCH_ARROW
token corresponding to acase
and increasing the CYC by one. There is no need to add one for theT_MATCH_DEFAULT
token, because this is followed by aT_MATCH_ARROW
token, and to do so would be to double-count that entry.PR to follow.
The text was updated successfully, but these errors were encountered: