Skip to content

Commit 5943d89

Browse files
authored
dev: php-tuf#142 Add PHPCS (php-tuf#145)
1 parent 98058ac commit 5943d89

3 files changed

Lines changed: 77 additions & 2 deletions

File tree

DEVELOP.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ To run a single test use PHPUnit's `--filter` option:
2121
ddev exec phpunit ./tests --debug --filter=testCannotProtectNonComposerRepository
2222
```
2323

24+
## Linting and fixing
25+
26+
Linting for syntax, then style:
27+
```
28+
ddev composer lint
29+
ddev composer phpcs
30+
```
31+
32+
Fixing style errors that can be automatically fixed:
33+
```
34+
ddev composer phpcbf
35+
```
36+
2437
## Static analysis
2538

2639
To run PHPStan against the codebase:

composer.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,22 @@
3939
"phpunit/phpunit": "^9.5",
4040
"symfony/process": "^6",
4141
"dms/phpunit-arraysubset-asserts": "^0.5.0",
42-
"phpstan/phpstan": "^2.1"
42+
"phpstan/phpstan": "^2.1",
43+
"squizlabs/php_codesniffer": "^4.0",
44+
"slevomat/coding-standard": "^8.28"
4345
},
4446
"scripts": {
47+
"phpcs": "phpcs",
48+
"phpcbf": "phpcbf",
4549
"phpstan": "phpstan",
4650
"test": [
4751
"phpunit ./tests --debug"
48-
]
52+
],
53+
"lint": "find src -name '*.php' -exec php -l {} \\;"
54+
},
55+
"config": {
56+
"allow-plugins": {
57+
"dealerdirect/phpcodesniffer-composer-installer": true
58+
}
4959
}
5060
}

phpcs.xml.dist

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset -->
4+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
name="PhpTuf"
6+
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd"
7+
>
8+
9+
<description>PHP TUF Composer Integration</description>
10+
11+
<arg name="colors"/>
12+
<arg name="parallel" value="10"/>
13+
14+
<file>src</file>
15+
<file>tests</file>
16+
17+
<!-- We basically follow PSR-2 -->
18+
<rule ref="PSR2">
19+
<exclude name="Generic.Files.LineLength.TooLong"/>
20+
</rule>
21+
22+
<!-- Since PSR-2 / PSR-12 say nothing about variable lettercase, we choose a standard. -->
23+
<rule ref="Squiz.NamingConventions.ValidVariableName.NotCamelCaps"/>
24+
<rule ref="Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps"/>
25+
<rule ref="Squiz.NamingConventions.ValidVariableName.StringNotCamelCaps"/>
26+
27+
<!-- PSR-2 doesn't enforce commenting standards.
28+
https://github.com/squizlabs/PHP_CodeSniffer/issues/2314#issuecomment-448008052
29+
https://www.php-fig.org/psr/psr-2/#7-conclusion
30+
Add PEAR's rule to make sure comment indentation matches code.
31+
@todo - breaks on switch statements.
32+
@see https://github.com/php-tuf/php-tuf/issues/58
33+
<rule ref="PEAR.WhiteSpace"/>
34+
-->
35+
36+
<!-- Specify array formatting -->
37+
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
38+
<rule ref="Generic.Arrays.ArrayIndent"/>
39+
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
40+
<rule ref="Squiz.Arrays.ArrayDeclaration">
41+
<!-- Disable some child rules that cause incorrect formatting. -->
42+
<exclude name="Squiz.Arrays.ArrayDeclaration.CloseBraceNotAligned"/>
43+
<exclude name="Squiz.Arrays.ArrayDeclaration.ValueNotAligned"/>
44+
<exclude name="Squiz.Arrays.ArrayDeclaration.SingleLineNotAllowed"/>
45+
<exclude name="Squiz.Arrays.ArrayDeclaration.KeyNotAligned"/>
46+
<exclude name="Squiz.Arrays.ArrayDeclaration.DoubleArrowNotAligned"/>
47+
</rule>
48+
49+
<!-- Find unused code -->
50+
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses"/>
51+
52+
</ruleset>

0 commit comments

Comments
 (0)