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
{{ message }}
Repository navigation
Reduce the cognitive complexity of Parser::handleArguments() #68
Is your feature request related to a problem? Please describe.
SonarCloud reports php:S3776 on 3.0.x: the cognitive complexity of Parser::handleArguments() is 28, and the limit is 15. The method does all the work in one loop:
long options (--foo, --foo value, --foo=bar)
short options (-k=value, -abc, -abc value)
positional arguments
the look-ahead for a value, and the move of the index past a value that was used
The nested if blocks and the index changes in the loop body make the method hard to read and to change. The loop variables are also single letters ($i, $j).
Describe the solution you'd like
Divide the method, with no change in behavior:
handleArguments() reads each argument, gets the next argument when it is a value, and sends the argument to one of three private methods.
handleLongOption(), handleShortOptions() and handlePositional() each store their result. Each one returns the number of arguments that it used (1, or 2 when it used the value).
Descriptive variable names in place of $i and $j.
Describe alternatives you've considered
Mark the issue as accepted in SonarCloud. The method then stays hard to change, and the next feature makes it more complex.
Additional context
Internal change only. The public API and the results do not change. The current test suite and Infection (MSI 100%) protect the behavior.
Activity
[#68] - Smaller handleArguments() with one handler per argument type
niden commentedon Dec 4, 2026
Resolved in #69