Skip to content

Commit 0deba34

Browse files
committed
feat: add phpmd & phpstan
1 parent 80fd80e commit 0deba34

File tree

3 files changed

+135
-5
lines changed

3 files changed

+135
-5
lines changed

phpcs.xml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,19 @@
3434
<rule ref="WordPress">
3535
<exclude name="WordPress.Files.FileName"/>
3636
<exclude name="WordPress.PHP.YodaConditions.NotYoda"/>
37-
<exclude name="Generic.Arrays.DisallowShortArraySyntax"/>
38-
<exclude name="WordPress.Security.EscapeOutput.OutputNotEscaped"/>
39-
<exclude name="PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket"/>
40-
<exclude name="PEAR.Functions.FunctionCallSignature.SpaceBeforeCloseBracket"/>
4137
<exclude name="WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceAfterOpenParenthesis"/>
4238
<exclude name="WordPress.WhiteSpace.OperatorSpacing.NoSpaceBefore"/>
4339
<exclude name="WordPress.WhiteSpace.OperatorSpacing.NoSpaceAfter"/>
4440
<exclude name="WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceBeforeCloseParenthesis"/>
4541
<exclude name="WordPress.DateTime.RestrictedFunctions.date_date"/>
42+
<exclude name="WordPress.Security.EscapeOutput.OutputNotEscaped"/>
43+
<exclude name="PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket"/>
44+
<exclude name="PEAR.Functions.FunctionCallSignature.SpaceBeforeCloseBracket"/>
45+
<exclude name="PEAR.Functions.FunctionCallSignature.Indent"/>
46+
<exclude name="Generic.Arrays.DisallowShortArraySyntax"/>
4647
<exclude name="Generic.Commenting.DocComment.MissingShort"/>
47-
<exclude name="PEAR.Functions.FunctionCallSignature.Indent"/>
48+
<exclude name="Universal.Operators.DisallowShortTernary.Found"/>
49+
<exclude name="Universal.Classes.RequireFinalClass.NonFinalClassFound"/>
4850
</rule>
4951

5052
<exclude-pattern>.idea/*</exclude-pattern>

phpmd.xml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<ruleset
3+
name="VersionEyeModule rules"
4+
xmlns="http://pmd.sf.net/ruleset/1.0.0"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
7+
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
8+
>
9+
<rule ref="rulesets/cleancode.xml">
10+
<exclude name="BooleanArgumentFlag" />
11+
<exclude name="ErrorControlOperator" />
12+
<exclude name="MissingImport" />
13+
<exclude name="StaticAccess" />
14+
</rule>
15+
<rule ref="rulesets/codesize.xml">
16+
<exclude name="CyclomaticComplexity" />
17+
<exclude name="ExcessiveClassComplexity" />
18+
<exclude name="NPathComplexity" />
19+
<exclude name="TooManyPublicMethods" />
20+
</rule>
21+
<rule ref="rulesets/design.xml">
22+
<exclude name="CouplingBetweenObjects" />
23+
<exclude name="ExitExpression" />
24+
</rule>
25+
<rule ref="rulesets/unusedcode.xml">
26+
<exclude name="UnusedFormalParameter" />
27+
<exclude name="UnusedLocalVariable" />
28+
</rule>
29+
<rule ref="rulesets/naming.xml">
30+
<exclude name="LongClassName" />
31+
<exclude name="LongVariable" />
32+
<exclude name="ShortVariable" />
33+
<exclude name="ShortMethodName" />
34+
</rule>
35+
36+
<rule ref="rulesets/codesize.xml/CyclomaticComplexity"
37+
since="0.1"
38+
message = "The {0} {1}() has a Cyclomatic Complexity of {2}. The configured cyclomatic complexity threshold is {3}."
39+
class="PHPMD\Rule\CyclomaticComplexity"
40+
externalInfoUrl="https://phpmd.org/rules/codesize.html#cyclomaticcomplexity">
41+
<priority>3</priority>
42+
<properties>
43+
<property name="reportLevel" description="The Cyclomatic Complexity reporting threshold" value="13"/>
44+
<property name="showClassesComplexity"
45+
description="Indicate if class average violation should be added to the report"
46+
value="true"/>
47+
<property name="showMethodsComplexity"
48+
description="Indicate if class average violation should be added to the report"
49+
value="true"/>
50+
</properties>
51+
</rule>
52+
<rule name="rulesets/codesize.xml/NPathComplexity"
53+
since="0.1"
54+
message="The {0} {1}() has an NPath complexity of {2}. The configured NPath complexity threshold is {3}."
55+
class="PHPMD\Rule\Design\NpathComplexity"
56+
externalInfoUrl="https://phpmd.org/rules/codesize.html#npathcomplexity">
57+
<priority>3</priority>
58+
<properties>
59+
<property name="minimum" description="The npath reporting threshold" value="300"/>
60+
</properties>
61+
</rule>
62+
<rule ref="rulesets/codesize.xml/TooManyPublicMethods"
63+
since="0.1"
64+
class="PHPMD\Rule\Design\TooManyPublicMethods"
65+
message="The {0} {1} has {2} public methods. Consider refactoring {1} to keep number of public methods under {3}."
66+
externalInfoUrl="https://phpmd.org/rules/codesize.html#toomanypublicmethods">
67+
<priority>3</priority>
68+
<properties>
69+
<property name="maxmethods" description="The method count reporting threshold" value="10"/>
70+
<property name="ignorepattern" description="Ignore methods matching this regex" value="(^(add|set|get|is|has|with|test))i"/>
71+
</properties>
72+
</rule>
73+
<rule name="rulesets/naming.xml/LongClassName"
74+
since="2.9"
75+
message="Avoid excessively long class names like {0}. Keep class name length under {1}."
76+
class="PHPMD\Rule\Naming\LongClassName"
77+
externalInfoUrl="https://phpmd.org/rules/naming.html#longclassname">
78+
<priority>3</priority>
79+
<properties>
80+
<property name="maximum" description="The class name length reporting threshold" value="40"/>
81+
<property name="subtract-suffixes" description="Comma-separated list of suffixes that will not count in the length of the class name. Only the first matching suffix will be subtracted." value="Interface, Subscriber"/>
82+
</properties>
83+
</rule>
84+
<rule rf="rulesets/naming.xml/LongVariable"
85+
since="0.2"
86+
message="Avoid excessively long variable names like {0}. Keep variable name length under {1}."
87+
class="PHPMD\Rule\Naming\LongVariable"
88+
externalInfoUrl="https://phpmd.org/rules/naming.html#longvariable">
89+
<priority>3</priority>
90+
<properties>
91+
<property name="maximum" description="The variable length reporting threshold" value="30"/>
92+
</properties>
93+
</rule>
94+
<rule ref="rulesets/naming.xml/ShortVariable"
95+
since="0.2"
96+
message="Avoid variables with short names like {0}. Configured minimum length is {1}."
97+
class="PHPMD\Rule\Naming\ShortVariable"
98+
externalInfoUrl="http://phpmd.org/rules/naming.html#shortvariable">
99+
<priority>3</priority>
100+
<properties>
101+
<property name="minimum" description="Minimum length for a variable, property or parameter name" value="3"/>
102+
<property name="exceptions" value="id,x,y" />
103+
</properties>
104+
</rule>
105+
<rule name="rulesets/naming.xml/ShortMethodName"
106+
since="0.2"
107+
message="Avoid using short method names like {0}::{1}(). The configured minimum method name length is {2}."
108+
class="PHPMD\Rule\Naming\ShortMethodName"
109+
externalInfoUrl="https://phpmd.org/rules/naming.html#shortmethodname">
110+
<priority>3</priority>
111+
<properties>
112+
<property name="minimum" description="Minimum length for a method or function name" value="3"/>
113+
<property name="exceptions" description="Comma-separated list of exceptions" value="id"/>
114+
</properties>
115+
</rule>
116+
</ruleset>

phpstan.neon

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
parameters:
2+
level: 6
3+
paths:
4+
- plugin.php
5+
- inc/
6+
excludePaths:
7+
- js/*
8+
- vendor/*
9+
- node_modules/*
10+
bootstrapFiles:
11+
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php
12+
- vendor/php-stubs/woocommerce-stubs/woocommerce-stubs.php

0 commit comments

Comments
 (0)