Skip to content

Commit 82cfff4

Browse files
committed
build: #2 phpcs and phpmd
1 parent bb900e8 commit 82cfff4

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

.git-pre-commit

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
set -e
3+
4+
FILES=$(git diff --diff-filter=d --name-only HEAD | { grep '.php$' || true; })
5+
for file in $FILES; do
6+
./vendor/bin/phpcs --extensions=php --standard=PSR12 "$file"
7+
./vendor/bin/phpmd "$file" text phpmd.xml
8+
done
9+
./vendor/bin/phpunit tests/

composer.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@
99
},
1010
"require-dev": {
1111
"fakerphp/faker": "^1.16",
12-
"phpunit/phpunit": "^9.5"
12+
"phpmd/phpmd": "^2.10",
13+
"phpunit/phpunit": "^9.5",
14+
"squizlabs/php_codesniffer": "^3.6"
1315
},
1416
"license": "Apache-2.0",
1517
"autoload": {
1618
"psr-4": { "Coding\\": "src/" }
1719
},
1820
"autoload-dev": {
1921
"psr-4": { "Coding\\Tests\\": "tests/" }
22+
},
23+
"scripts": {
24+
"post-install-cmd": [
25+
"php -r \"if (is_dir('.git/hooks/')) {copy('.git-pre-commit', '.git/hooks/pre-commit'); chmod('.git/hooks/pre-commit', 0755);}\""
26+
]
2027
}
2128
}

phpmd.xml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<pmd>
3+
<rule ref="rulesets/cleancode.xml">
4+
<exclude name="StaticAccess" />
5+
</rule>
6+
7+
<rule ref="rulesets/codesize.xml" />
8+
<rule ref="rulesets/controversial.xml" />
9+
<rule ref="rulesets/design.xml" />
10+
11+
<rule ref="rulesets/naming.xml">
12+
<exclude name="ShortVariable" />
13+
</rule>
14+
15+
<rule ref="rulesets/naming.xml/ShortVariable"
16+
since="0.2"
17+
message="Avoid variables with short names like {0}. Configured minimum length is {1}."
18+
class="PHPMD\Rule\Naming\ShortVariable"
19+
externalInfoUrl="http://phpmd.org/rules/naming.html#shortvariable">
20+
<priority>3</priority>
21+
<properties>
22+
<property name="minimum" description="Minimum length for a variable, property or parameter name" value="3"/>
23+
<property name="exceptions" value="id,q,w,i,j,k,v,e,f,fp" />
24+
</properties>
25+
</rule>
26+
27+
<rule ref="rulesets/unusedcode.xml" />
28+
</pmd>

0 commit comments

Comments
 (0)