Closed simesy closed 6 years ago
That document only describes how to define the rulesets you want.
ruleset: ['cleancode', 'codesize', 'naming']
I want to pass parameters into the naming
ruleset.
@simesy in grumphp.yml:
phpmd:
exclude:
- tests/
- helpers.php
ruleset: ['/phpmd/custom.xml']
triggered_by: ['php']
where /phpmd
is a directory on project's root
Custom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="phpmd ruleset"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>
Inspired by https://github.com/phpmd/phpmd/issues/137
using http://phpmd.org/documentation/creating-a-ruleset.html
</description>
<!-- The rulesets are imported, in this case all. -->
<rule ref="/phpmd/cleancode.xml">
<exclude name="StaticAccess"/>
</rule>
<rule ref="/phpmd/codesize.xml/CyclomaticComplexity"/>
<rule ref="/phpmd/codesize.xml/NPathComplexity"/>
<rule ref="/phpmd/codesize.xml/ExcessiveMethodLength"/>
<rule ref="/phpmd/codesize.xml/ExcessiveClassLength"/>
<rule ref="/phpmd/codesize.xml/ExcessiveParameterList"/>
<rule ref="/phpmd/codesize.xml/ExcessivePublicCount"/>
<rule ref="/phpmd/codesize.xml/TooManyFields"/>
<rule ref="/phpmd/codesize.xml/TooManyMethods">
<properties>
<property name="maxmethods" value="30"/>
</properties>
</rule>
<rule ref="/phpmd/codesize.xml/ExcessiveClassComplexity"/>
<rule ref="/phpmd/controversial.xml"/>
<rule ref="/phpmd/design.xml">
<exclude name="CouplingBetweenObjects"/>
</rule>
<!-- beware the façades -->
<rule ref="/phpmd/design.xml/CouplingBetweenObjects">
<properties>
<property name="minimum" value="20"/>
</properties>
</rule>
<!-- importing naming and excluding ShortVariable to be adjusted after -->
<rule ref="/phpmd/naming.xml">
<exclude name="ShortVariable"/>
<exclude name="ShortMethodName"/>
</rule>
<rule ref="/phpmd/naming.xml/ShortVariable"
since="0.2"
message="Avoid variables with short names like {0}. Configured minimum length is {1}."
class="PHPMD\Rule\Naming\ShortVariable"
externalInfoUrl="http://phpmd.org/rules/naming.html#shortvariable">
<priority>3</priority>
<properties>
<property name="minimum" description="Minimum length for a variable, property or parameter name" value="2"/>
<property name="exceptions" value="id,q,w,i,j,v,e,f,fp" />
</properties>
</rule>
<rule name="/phpmd/naming.xml/ShortMethodName"
since="0.2"
message="Avoid using short method names like {0}::{1}(). The configured minimum method name length is {2}."
class="PHPMD\Rule\Naming\ShortMethodName"
externalInfoUrl="http://phpmd.org/rules/naming.html#shortmethodname">
<priority>3</priority>
<properties>
<property name="minimum" description="Minimum length for a method or function name" value="2"/>
<property name="exceptions" description="Comma-separated list of exceptions" value=""/>
</properties>
</rule>
<rule ref="/phpmd/unusedcode.xml">
<exclude name="UnusedFormalParameter"/>
<exclude name="UnusedLocalVariable"/>
</rule>
</ruleset>
Oh great thanks!
PHPMD accepts parameters to it's rulesets, however I'm unable to find any documentation of how to pass them in from grumphp.yml.