Skip to content

Commit 9123be8

Browse files
authored
MQE-525: Include PHP Mess Detector to required checks for MFTF
- updated composer to pull phpmd, ported Magento rulesets to work with phpmd on MFTF - updated static-checks with PHPMD, no changes to devops required - commented Mess Detector Lines out to enable them during MQE-590
1 parent 62780b4 commit 9123be8

File tree

5 files changed

+122
-1
lines changed

5 files changed

+122
-1
lines changed

bin/static-checks

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ vendor/bin/phpcs ./dev/tests/verification --standard=./dev/tests/static/Magento
99
echo "===============================COPY PASTE DETECTOR REPORT==============================="
1010
vendor/bin/phpcpd ./src
1111

12+
# Uncomment lines as part of MQE-590
13+
# echo "===============================PHP MESS DETECTOR REPORT==============================="
14+
# vendor/bin/phpmd ./src text /dev/tests/static/Magento/CodeMessDetector/ruleset.xml --exclude _generated
15+
1216
echo "===============================MAGENTO COPYRIGHT REPORT==============================="
1317
bin/copyright-check
18+

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"sebastian/phpcpd": "~3.0",
1717
"brainmaestro/composer-git-hooks": "^2.3",
1818
"codeception/aspect-mock": "^2.0",
19-
"codacy/coverage": "^1.4"
19+
"codacy/coverage": "^1.4",
20+
"phpmd/phpmd": "^2.6.0"
2021
},
2122
"autoload": {
2223
"psr-4": {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CodeMessDetector\Rule\Design;
8+
9+
use PHPMD\AbstractNode;
10+
use PHPMD\AbstractRule;
11+
use PHPMD\Rule\ClassAware;
12+
use PHPMD\Rule\MethodAware;
13+
14+
/**
15+
* Magento is a highly extensible and customizable platform.
16+
* Usage of final classes and methods is prohibited.
17+
*/
18+
class FinalImplementation extends AbstractRule implements ClassAware, MethodAware
19+
{
20+
/**
21+
* @inheritdoc
22+
*/
23+
public function apply(AbstractNode $node)
24+
{
25+
if ($node->isFinal()) {
26+
$this->addViolation($node, [$node->getType(), $node->getFullQualifiedName()]);
27+
}
28+
}
29+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<ruleset name="Magento Specific Design Rules"
9+
xmlns="http://pmd.sf.net/ruleset/1.0.0"
10+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
11+
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
12+
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
13+
<rule name="FinalImplementation"
14+
class="Magento\CodeMessDetector\Rule\Design\FinalImplementation"
15+
message= "The {0} {1} declared as final.">
16+
<description>
17+
<![CDATA[
18+
Final keyword is prohibited in Magento as this decreases extensibility and customizability.
19+
Final classes and method are not compatible with plugins and proxies.
20+
]]>
21+
</description>
22+
<priority>1</priority>
23+
<properties />
24+
<example>
25+
<![CDATA[
26+
final class Foo
27+
{
28+
public function bar() {}
29+
}
30+
class Baz {
31+
final public function bad() {}
32+
}
33+
]]>
34+
</example>
35+
</rule>
36+
</ruleset>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version='1.0' encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<ruleset name="Magento PHPMD rule set" xmlns="http://pmd.sf.net/ruleset/1.0.0"
9+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
11+
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
12+
<description>Magento Code Check Rules</description>
13+
<php-includepath>../../../static</php-includepath>
14+
15+
<!-- Code Size Rules -->
16+
<rule ref="rulesets/codesize.xml/CyclomaticComplexity" />
17+
<rule ref="rulesets/codesize.xml/NPathComplexity" />
18+
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength" />
19+
<rule ref="rulesets/codesize.xml/ExcessiveParameterList" />
20+
<rule ref="rulesets/codesize.xml/ExcessivePublicCount" />
21+
<rule ref="rulesets/codesize.xml/TooManyFields" />
22+
<rule ref="rulesets/codesize.xml/ExcessiveClassComplexity">
23+
<properties>
24+
<property name="maximum" value="100" />
25+
</properties>
26+
</rule>
27+
28+
<!-- Unused code rules -->
29+
<rule ref="rulesets/unusedcode.xml" />
30+
31+
<!-- Code design rules -->
32+
<rule ref="rulesets/design.xml/ExitExpression" />
33+
<rule ref="rulesets/design.xml/EvalExpression" />
34+
<rule ref="rulesets/design.xml/GotoStatement" />
35+
<rule ref="rulesets/design.xml/NumberOfChildren" />
36+
<rule ref="rulesets/design.xml/DepthOfInheritance">
37+
<properties>
38+
<property name="minimum" value="8" />
39+
</properties>
40+
</rule>
41+
<rule ref="rulesets/design.xml/CouplingBetweenObjects" />
42+
43+
<!-- Naming Rules -->
44+
<rule ref="rulesets/naming.xml/ShortMethodName" />
45+
<rule ref="rulesets/naming.xml/ConstantNamingConventions" />
46+
<rule ref="rulesets/naming.xml/BooleanGetMethodName" />
47+
48+
<!-- Magento Specific Rules -->
49+
<rule ref="Magento/CodeMessDetector/resources/rulesets/design.xml/FinalImplementation" />
50+
</ruleset>

0 commit comments

Comments
 (0)