Skip to content

Pay down the two baselined PHPMD complexity findings in NamedParametersSniff #13

Description

@rubenvdlinde

Pay down the two baselined PHPMD complexity findings in NamedParametersSniff

phpmd.baseline.xml was introduced in the chore/measure-strict-gate-2026-08-02 PR ("make composer check:strict an honest gate"). It contains exactly two entries, and this issue tracks removing both.

The two baselined findings

rule location measured threshold
WeightedMethodCount (ExcessiveClassComplexity) NamedParametersSniff class 65 50
CyclomaticComplexity NamedParametersSniff::hasUnnamedArguments() 20 15

Measured with ./vendor/bin/phpmd phpcs-custom-sniffs text phpmd.xml inside nextcloud:32-apache (PHP 8.3.32).

Why they were baselined rather than fixed

Neither is a defect — both are complexity/style findings, and they are largely inherent to hand-written PHP token-stream parsing, which is unavoidably branchy.

They were not fixed in that PR on purpose: reducing them means restructuring the control flow of the sniff that enforces our fleet-wide named-parameter rule, and that PR's own finding was that this file had never been linted or analysed at all (every tool was aimed at a lib/ directory that does not exist in this repo). Changing the behaviour of an unproven sniff inside a gate-repair PR would have been the wrong risk to take.

The baseline entries are pinned to a specific rule + file (+ method), so any new complexity violation still fails the gate. Verified with a positive control.

What to do

  1. Extract the argument-scanning branches of hasUnnamedArguments() into small named helpers (the T_* token dispatch is the bulk of the 20).
  2. Re-run ./vendor/bin/phpmd phpcs-custom-sniffs text phpmd.xml.
  3. Delete the corresponding entries from phpmd.baseline.xml — and delete the file entirely once both are gone.
  4. The sniff has no test suite. Adding one before refactoring is strongly preferable, since the sniff is what enforces the named-parameter rule across the fleet.

Related, worth doing first

phpcs-custom-sniffs/CustomSniffs/Sniffs/Functions/NamedParametersSniff.php is byte-identical across openklant, opentalk, openzaak and valtimo — and so is this debt, this baseline, and this issue. The sniff should live in one shared package consumed by all four rather than being copy-pasted; otherwise this refactor has to be done four times and the copies will drift.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions