Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV-30 - Move phpmd config to phpmd.xml. #234

Merged
merged 5 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ phpmd:
# Output format for phpmd.
format: text
# Comma-separated list of ruleset paths or names.
rulesets: "${build.thebuild.dir}/defaults/standard/phpmd.xml"
rulesets: "${build.dir}/phpmd.xml"
# File extensions to review.
suffixes: php,inc,module,theme,profile,install,test

Expand Down
5 changes: 2 additions & 3 deletions defaults/install/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,8 @@
<exec command="vendor/bin/phpcs" logoutput="true" checkreturn="true" />

<!-- Run PHP Mess Detector. -->
<property name="phpmd.command" value="vendor/bin/phpmd ${phpmd.directories} ${phpmd.format} ${phpmd.rulesets} --suffixes ${phpmd.suffixes}" />
<echo msg="$> ${phpmd.command}" />
<exec command="${phpmd.command}" logoutput="true" checkreturn="true" />
<echo msg="$> vendor/bin/phpmd" />
<exec command="vendor/bin/phpmd ${phpmd.directories} ${phpmd.format} ${phpmd.rulesets} --suffixes ${phpmd.suffixes}" logoutput="true" checkreturn="true" />

<!-- Run Drupal Check. -->
<foreach list="${drupal-check.directories}" param="drupal-check.dir" target="drupal-check" />
Expand Down
78 changes: 78 additions & 0 deletions defaults/install/phpmd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0"?>
<ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PMD Ruleset for Drupal" xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>
A PMD Ruleset for Drupal coding standards.
</description>

<!--
Include each rule explicitly so we know what we have.
@see https://github.com/phpmd/phpmd/blob/master/src/main/resources/rulesets/
-->

<!-- Clean Code -->
<!--
These don't align with Drupal standards, so they are excluded.
@todo Static calls are hard to test and extend, is there a way to whitelist the ones that are OK?
<rule ref="rulesets/cleancode.xml/BooleanArgumentFlag"/>
<rule ref="rulesets/cleancode.xml/ElseExpression"/>
<rule ref="rulesets/cleancode.xml/StaticAccess"/>
-->

<!-- Code Size -->
<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>
<rule ref="rulesets/codesize.xml/NPathComplexity"/>
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>
<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>
<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>
<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>
<rule ref="rulesets/codesize.xml/TooManyFields"/>

<!-- Controversial -->
<rule ref="rulesets/controversial.xml/Superglobals"/>
<!--
These checks do not need to be included since PHPCS will check for style.
<rule ref="rulesets/controversial.xml/CamelCaseClassName"/>
<rule ref="rulesets/controversial.xml/CamelCasePropertyName"/>
<rule ref="rulesets/controversial.xml/CamelCaseMethodName"/>
<rule ref="rulesets/controversial.xml/CamelCaseParameterName"/>
<rule ref="rulesets/controversial.xml/CamelCaseVariableName"/>
-->

<!-- Design -->
<rule ref="rulesets/design.xml/ExitExpression"/>
<rule ref="rulesets/design.xml/EvalExpression"/>
<rule ref="rulesets/design.xml/GotoStatement"/>
<rule ref="rulesets/design.xml/NumberOfChildren"/>
<rule ref="rulesets/design.xml/DepthOfInheritance"/>
<rule ref="rulesets/design.xml/CouplingBetweenObjects"/>
<rule ref="rulesets/design.xml/DevelopmentCodeFragment"/>

<!-- Naming -->
<rule ref="rulesets/naming.xml/ShortVariable">
<properties>
<!-- Allow $id as a variable name. -->
<property name="exceptions" description="Comma-separated list of exceptions" value="id"/>
</properties>
</rule>
<rule ref="rulesets/naming.xml/LongVariable">
<properties>
<!-- Bump variable length to a more reasonable number. -->
<property name="maximum" description="The variable length reporting threshold" value="35"/>
</properties>
</rule>
<rule ref="rulesets/naming.xml/ShortMethodName"/>
<rule ref="rulesets/naming.xml/ConstructorWithNameAsEnclosingClass"/>
<rule ref="rulesets/naming.xml/ConstantNamingConventions"/>
<rule ref="rulesets/naming.xml/BooleanGetMethodName"/>

<!-- Unused Code -->
<rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/>
<rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/>
<rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/>
<!--
Hooks often have unused parameters, so ignore this warning.
@todo is there a way to allow unused parameters in hooks but not elsewhere?
<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>
-->

</ruleset>
21 changes: 21 additions & 0 deletions targets/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,27 @@
</filterchain>
</copy>

<!-- Copy the phpmd.xml file template.
-->
<echo>Updating phpmd.xml file for project root.</echo>
<if>
<equals arg1="${build.host}" arg2="acquia"/>
<then>
<property name="phpmd_dir" value="docroot"/>
</then>
<else>
<property name="phpmd_dir" value="web"/>
</else>
</if>
<copy file="${phing.dir.install}/../defaults/install/phpmd.xml" tofile="${application.startdir}/phpmd.xml" overwrite="true">
<filterchain>
<replacetokens>
<token key="projectname" value="${projectname}" />
<token key="webroot" value="${phpmd_dir}" />
</replacetokens>
</filterchain>
</copy>

<!-- Copy other templates into place.
These copy commands use <expandproperties /> for property substitution.
-->
Expand Down