Skip to content

Reduce the cognitive complexity of Parser::handleArguments() - #69

Merged
niden merged 1 commit into
3.0.xfrom
T68-parser-complexity
Dec 4, 2026
Merged

niden merged 1 commit into
3.0.xfrom
T68-parser-complexity

Conversation

@niden

@niden niden commented Dec 4, 2026

Copy link
Copy Markdown
Member

Hello!

In raising this pull request, I confirm the following:

  • I have read and understood the Contributing Guidelines
  • I have checked that another pull request for this purpose does not exist
  • I wrote some tests for this PR
  • I have updated the relevant CHANGELOG

Small description of change:

Stacked on #67. Merge #67 first.

Fixes SonarCloud php:S3776 (cognitive complexity 28, limit 15) in Parser::handleArguments(). The behavior does not change.

  • handleArguments() reads each argument and gets the next argument when it is a value (it exists and does not start with -). A match then sends the argument to one handler.
  • handleLongOption(), handleShortOptions() and handlePositional() store the result. Each returns the number of arguments it used: 1, or 2 when it used the value. The loop moves by that number.
  • No one-letter variables: $position, $argument, $next, $value and $letters replace $i, $j and $chars.

There are no new tests and no CHANGELOG line, because this is an internal change. The current suite and Infection protect the behavior.

Results in the PHP 8.3 container: 65 tests pass, line coverage 100% (75/75), Infection MSI 100% and covered MSI 100% (120 mutants, no escaped). PHPCS, PHPStan and PHP CS Fixer pass.

Thanks

@niden niden added the enhancement New feature or request label Dec 4, 2026
@niden niden self-assigned this Dec 4, 2026
@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

Code Metrics Report

master (4b6c04c) T68-parser-complexity (8fbe7d3) +/-
Coverage 100.0% 100.0% 0.0%
Test Execution Time 1s 0s -1s
Details
  |                     | master (4b6c04c) |     T68-parser-complexity      | +/-  |
  |                     |                  |           (8fbe7d3)            |      |
  |---------------------|------------------|--------------------------------|------|
  | Coverage            |           100.0% |                         100.0% | 0.0% |
  |   Files             |                1 |                              1 |    0 |
  |   Lines             |               71 |                             75 |   +4 |
+ |   Covered           |               71 |                             75 |   +4 |
+ | Test Execution Time |               1s |                             0s |  -1s |

Code coverage of files in pull request scope (100.0% → 100.0%, patch 100.0%)

Files Coverage +/- Patch Coverage Status
src/Parser.php 100.0% 0.0% 100.0% modified

Reported by octocov

Base automatically changed from T66-empty-argument to 3.0.x December 4, 2026 21:13
@niden
niden merged commit 9e42784 into 3.0.x Dec 4, 2026
14 checks passed
@niden
niden deleted the T68-parser-complexity branch December 4, 2026 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant