Skip to content

Reduce the cognitive complexity of Parser::handleArguments() #68

Done

Description

@niden

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

  1. added
    enhancement
    on Dec 4, 2026
  2. self-assigned this
    on Dec 4, 2026
  3. added theissue type on Dec 4, 2026
  4. added a commit that references this issue on Dec 4, 2026
  5. niden commented on Dec 4, 2026

    @niden
    SponsorMemberAuthor

    Resolved in #69

  6. moved this from Backlog to Implemented in Phalcon v5on Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

Projects

  • Status
    Implemented

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions