Skip to content

Commit 11c54b6

Browse files
rubenvdlindeRuben van der Linde
andauthored
chore(quality): point PHPMD at the central ruleset (#498)
phpmd.xml becomes a 9-line stub referencing vendor/conduction/hydra-gates/quality-config/phpmd.xml, and the local phpmd-unusedparams.xml is deleted in favour of the central copy, which the unused-parameters leg of the composer phpmd script now points at. Both legs, their flags and the worst-exit-code behaviour are unchanged. Co-authored-by: Ruben van der Linde <release-bot@conduction.nl>
1 parent d788cd5 commit 11c54b6

3 files changed

Lines changed: 5 additions & 159 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"phpcs": "./vendor/bin/phpcs --standard=phpcs.xml",
2828
"phpcs:fix": "./vendor/bin/phpcbf --standard=phpcs.xml",
2929
"phpcs:output": "./vendor/bin/phpcs --standard=phpcs.xml --report=json lib/ 2>/dev/null | tail -1 > phpcs-output.json",
30-
"phpmd": "E=0; ./vendor/bin/phpmd lib text phpmd.xml --baseline-file phpmd.baseline.xml || E=$?; ./vendor/bin/phpmd lib text phpmd-unusedparams.xml --baseline-file phpmd.baseline.xml || E=$?; exit $E",
30+
"phpmd": "E=0; ./vendor/bin/phpmd lib text phpmd.xml --baseline-file phpmd.baseline.xml || E=$?; ./vendor/bin/phpmd lib text vendor/conduction/hydra-gates/quality-config/phpmd-unusedparams.xml --baseline-file phpmd.baseline.xml || E=$?; exit $E",
3131
"phpmetrics": "./vendor/bin/phpmetrics --report-html=phpmetrics lib/",
3232
"phpmetrics:violations": "./vendor/bin/phpmetrics --violations-xml=phpmetrics/violations.xml lib/",
3333
"psalm": "if [ -f vendor/bin/psalm ]; then ./vendor/bin/psalm --threads=1 --no-cache; else echo 'Psalm not installed, skipping...'; fi",

phpmd-unusedparams.xml

Lines changed: 0 additions & 40 deletions
This file was deleted.

phpmd.xml

Lines changed: 4 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,9 @@
11
<?xml version="1.0"?>
2-
<ruleset name="SoftwareCatalog Nextcloud Rules"
2+
<ruleset name="softwarecatalog"
33
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0
6-
http://pmd.sourceforge.net/ruleset_xml_schema.xsd">
5+
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_xml_schema.xsd">
6+
<description>softwarecatalog — Conduction PHPMD ruleset (single source: conduction/hydra-gates).</description>
77

8-
<description>
9-
This is a custom ruleset for SoftwareCatalog Nextcloud.
10-
</description>
11-
12-
<!-- Clean Code Rules -->
13-
<rule ref="rulesets/cleancode.xml/BooleanArgumentFlag"/>
14-
<rule ref="rulesets/cleancode.xml/ElseExpression"/>
15-
<rule ref="rulesets/cleancode.xml/StaticAccess"/>
16-
<rule ref="rulesets/cleancode.xml/IfStatementAssignment"/>
17-
<rule ref="rulesets/cleancode.xml/DuplicatedArrayKey"/>
18-
<rule ref="rulesets/cleancode.xml/MissingImport"/>
19-
<rule ref="rulesets/cleancode.xml/UndefinedVariable"/>
20-
<rule ref="rulesets/cleancode.xml/ErrorControlOperator"/>
21-
22-
<!-- Code Size Rules -->
23-
<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>
24-
<rule ref="rulesets/codesize.xml/NPathComplexity"/>
25-
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>
26-
<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>
27-
<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>
28-
<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>
29-
<rule ref="rulesets/codesize.xml/TooManyFields"/>
30-
<rule ref="rulesets/codesize.xml/TooManyMethods"/>
31-
<rule ref="rulesets/codesize.xml/TooManyPublicMethods"/>
32-
<rule ref="rulesets/codesize.xml/ExcessiveClassComplexity"/>
33-
34-
<!-- Controversial Rules -->
35-
<rule ref="rulesets/controversial.xml/Superglobals"/>
36-
<rule ref="rulesets/controversial.xml/CamelCaseClassName"/>
37-
<rule ref="rulesets/controversial.xml/CamelCasePropertyName"/>
38-
<rule ref="rulesets/controversial.xml/CamelCaseMethodName"/>
39-
<!-- CamelCaseParameterName removed - we allow leading underscores on parameters (convention for unused/config params) -->
40-
<!-- <rule ref="rulesets/controversial.xml/CamelCaseParameterName"/> -->
41-
<!-- CamelCaseVariableName removed - we allow leading underscores on variables (convention for unused loop vars) -->
42-
<!-- <rule ref="rulesets/controversial.xml/CamelCaseVariableName"/> -->
43-
44-
<!-- Design Rules -->
45-
<rule ref="rulesets/design.xml/ExitExpression"/>
46-
<rule ref="rulesets/design.xml/EvalExpression"/>
47-
<rule ref="rulesets/design.xml/GotoStatement"/>
48-
<rule ref="rulesets/design.xml/NumberOfChildren"/>
49-
<rule ref="rulesets/design.xml/DepthOfInheritance"/>
50-
<rule ref="rulesets/design.xml/CouplingBetweenObjects"/>
51-
<!-- DevelopmentCodeFragment MUST carry ignore-namespaces=true, or it is dead
52-
code in this ruleset. See ConductionNL/openregister#2286.
53-
54-
PDepend resolves an unqualified call inside a namespaced file to the
55-
CURRENT-NAMESPACE-qualified image, so `var_dump($x)` in
56-
`namespace OCA\MyApp\Service;` reaches the rule as
57-
`OCA\MyApp\Service\var_dump`, which never matches the
58-
`unwanted-functions` list. All of our production PHP is namespaced, so
59-
with the default (false) the rule catches nothing anywhere.
60-
61-
Measured on phpmd 2.15.0 / PHP 8.3.32: byte-identical probe class,
62-
namespaced -> exit 0, non-namespaced -> exit 2. With
63-
ignore-namespaces=true the rule strips the enclosing namespace before
64-
matching, the namespaced probe is reported (exit 2), and a clean
65-
namespaced file stays exit 0.
66-
67-
Note: hydra gate 2 (forbidden-patterns) independently greps lib/ for
68-
var_dump / die / error_log / print_r / dd / dump and is the broader
69-
control - it also catches calls outside methods, which this rule (a
70-
MethodAware/FunctionAware rule) cannot see. This rule is the
71-
`composer check:strict` half of the same guard; keep both. -->
72-
<rule ref="rulesets/design.xml/DevelopmentCodeFragment">
73-
<properties>
74-
<property name="ignore-namespaces" value="true"/>
75-
</properties>
76-
</rule>
77-
<rule ref="rulesets/design.xml/EmptyCatchBlock"/>
78-
<rule ref="rulesets/design.xml/CountInLoopExpression"/>
79-
80-
<!-- Naming Rules -->
81-
<rule ref="rulesets/naming.xml/LongClassName"/>
82-
<rule ref="rulesets/naming.xml/ShortClassName"/>
83-
<!-- ShortVariable configured with allowlist of idiomatic short names -->
84-
<rule ref="rulesets/naming.xml/ShortVariable">
85-
<properties>
86-
<property name="minimum" value="3" />
87-
<property name="exceptions" value="id,db,qb,op,ui,io,gc,tz,pk,fk,to,ch,a,b,l,v,c,t,r,f,n,k,e" />
88-
</properties>
89-
</rule>
90-
<rule ref="rulesets/naming.xml/LongVariable"/>
91-
<rule ref="rulesets/naming.xml/ShortMethodName"/>
92-
<rule ref="rulesets/naming.xml/ConstructorWithNameAsEnclosingClass"/>
93-
<rule ref="rulesets/naming.xml/ConstantNamingConventions"/>
94-
<rule ref="rulesets/naming.xml/BooleanGetMethodName"/>
95-
96-
<!-- Unused Code Rules -->
97-
<rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/>
98-
<rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/>
99-
<rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/>
100-
<!-- UnusedFormalParameter is NOT declared here. It lives alone in
101-
phpmd-unusedparams.xml, which is run as a second leg by the "phpmd"
102-
composer script.
103-
104-
Why: this rule used to carry a NESTED
105-
<exclude-pattern>*Migration*</exclude-pattern>
106-
meant to spare lib/Migration, whose changeSchema/preSchemaChange/
107-
postSchemaChange signatures are mandated by OCP\Migration\IMigrationStep
108-
and cannot drop their unused parameters. That pattern was INERT: PHPMD
109-
2.15 reads exclude-patterns in RuleSetFactory::getIgnorePattern(), which
110-
walks $xml->children() - i.e. only elements DIRECTLY under <ruleset>. A
111-
nested one parses without error and does nothing, so lib/Migration was
112-
always scanned by this rule (ConductionNL/.github#155).
113-
114-
Moving the pattern up to the top level of THIS file would make it
115-
effective, but it is applied by PDepend's ExcludePathFilter at
116-
file-collection time, so it drops lib/Migration from EVERY rule in the
117-
ruleset - real complexity, StaticAccess and method-length findings in
118-
migrations would silently vanish.
119-
120-
Isolating the rule in its own ruleset gives the exclusion a top-level
121-
home that scopes it to this one rule, while the main leg above keeps
122-
analysing lib/Migration with everything else. -->
8+
<rule ref="vendor/conduction/hydra-gates/quality-config/phpmd.xml"/>
1239
</ruleset>

0 commit comments

Comments
 (0)