Skip to content

Commit 62f596b

Browse files
authored
feat: Update dependencies. Support PHP 8.4. Support Pixel sniffs. Dis… (#12)
* feat: Update dependencies. Support PHP 8.4. Support Pixel sniffs. Disallow switch sniff. * feat: Update readme. * fix(dependencies): Remove composer.lock. No need anymore. * chore(dependencies): Added composer.lock to gitignore. * feat(rules): Removed rule "Generic.CodeAnalysis.UselessOverridingMethod". * feat(rules): Removed null-default values for Jump Statement sniff which in slevomat 8.16.0 make error. * feat(rules): Update slevomat to 8.16.0. Added composer normalizer. Update class structure with reflection for new group "invoke method".
1 parent d2fae23 commit 62f596b

21 files changed

+191
-477
lines changed

.github/workflows /php-ci.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/.idea/
22
/vendor/
3+
composer.lock

README.md

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,48 @@
33
This package provides PHPCS rule set for coding standards in Pixel Federation. It should be included into
44
each project maintained by Pixel Federation that uses PHP Code Sniffer [PHPCS](https://github.com/squizlabs/PHP_CodeSniffer).
55

6-
## Example usage
6+
## Migration from v4 to v5
7+
Generic ruleset was removed. Now there are only rulesets for specific PHP versions.
78

8-
### 1) Install composer dependencies
9+
Replace (in your ruleset) reference to file
10+
```vendor/pixelfederation/coding-standards/phpcs.ruleset.xml```
11+
with
12+
```vendor/pixelfederation/coding-standards/phpcs.ruleset.84.xml```
13+
for PHP 8.4.
14+
15+
## How to use
16+
17+
### Install composer dependencies
918

1019
```bash
11-
composer require pixelfederation/coding-standards:^2.0 --dev
20+
composer require --dev pixelfederation/coding-standards:^5.0
1221
```
1322

14-
### 2) Ruleset creation
23+
### Supported versions
24+
25+
For each php version there are 2 versions of the ruleset. One for DDD projects and one for Non-DDD projects.
1526

16-
Create a file named `phpcs.ruleset.xml` to the root folder of your project with the following content:
27+
For example for PHP 8.4:
28+
```
29+
vendor/pixelfederation/coding-standards/phpcs.ruleset.84.xml
30+
OR
31+
vendor/pixelfederation/coding-standards/phpcs.ruleset.84.non-ddd.xml
32+
```
33+
34+
### Ruleset creation
35+
36+
Create a file named `phpcs.ruleset.xml` in the root folder of your project with the following content:
1737

1838
```xml
1939
<?xml version="1.0"?>
2040
<ruleset name="PixelFederation">
21-
2241
<description>PixelFederation rule set.</description>
2342

24-
<config name="testVersion" value="8.1"/><!-- insert your php version -->
2543
<exclude-pattern>tests/</exclude-pattern>
26-
<rule ref="vendor/pixelfederation/coding-standards/phpcs.ruleset.xml">
27-
<!-- old projects may want to exclude these rules: -->
28-
<!-- <exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming"/>
29-
<exclude name="SlevomatCodingStandard.Classes.SuperfluousTraitNaming"/>
30-
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming"/>
31-
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming"/> -->
32-
<!-- <exclude name="SlevomatCodingStandard.Files.FunctionLength"/> -->
33-
</rule>
3444

35-
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
36-
<properties>
37-
<property name="rootNamespaces" type="array">
38-
<element key="src" value="Your\Root\Namespace"/><!-- add your namespaces -->
39-
</property>
40-
</properties>
45+
<rule ref="vendor/pixelfederation/coding-standards/phpcs.ruleset.84.xml"> <!-- Insert version for your php version -->
46+
<!-- You can exclude some rules here -->
47+
<exclude name="SlevomatCodingStandard.Files.FunctionLength"/>
4148
</rule>
4249
</ruleset>
4350
```
@@ -47,15 +54,15 @@ Create a file named `phpcs.ruleset.xml` to the root folder of your project with
4754
In your project directory run this command:
4855

4956
```bash
50-
vendor/bin/phpcs --standard=phpcs.ruleset.xml --extensions=php --tab-width=4 -sp src
57+
vendor/bin/phpcs --standard=phpcs.ruleset.xml src
5158
```
5259

5360
### Automatically fixing errors
5461

5562
In your project directory run this command:
5663

5764
```bash
58-
vendor/bin/phpcbf --standard=phpcs.ruleset.xml --extensions=php --tab-width=4 -sp src
65+
vendor/bin/phpcbf --standard=phpcs.ruleset.xml src
5966
```
6067

6168
## Additional links

composer.json

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,60 @@
11
{
22
"name": "pixelfederation/coding-standards",
3-
"homepage": "https://github.com/pixelfederation/coding-standards",
4-
"type": "library",
53
"description": "Standardized PHPCS sniffs for backend developers.",
64
"license": "BSD-3-Clause",
5+
"type": "library",
76
"authors": [
87
{
98
"name": "Martin Fris",
109
"email": "mfris@pixelfederation.com"
1110
}
1211
],
12+
"homepage": "https://github.com/pixelfederation/coding-standards",
1313
"require": {
1414
"php": "^8.1",
1515
"phpcompatibility/php-compatibility": "^9.3.5",
16-
"slevomat/coding-standard": "^8.12.1",
16+
"slevomat/coding-standard": "^8.16.0",
1717
"squizlabs/php_codesniffer": "^3.7.2"
1818
},
19+
"require-dev": {
20+
"ergebnis/composer-normalize": "^2.45"
21+
},
1922
"autoload": {
2023
"psr-4": {
2124
"PixelFederation\\CodingStandards\\": "src/"
2225
}
2326
},
27+
"autoload-dev": {
28+
"psr-4": {
29+
"Tests\\": [
30+
"tests/"
31+
]
32+
}
33+
},
2434
"config": {
25-
"sort-packages": true,
2635
"allow-plugins": {
27-
"dealerdirect/phpcodesniffer-composer-installer": true
28-
}
36+
"dealerdirect/phpcodesniffer-composer-installer": true,
37+
"ergebnis/composer-normalize": true
38+
},
39+
"sort-packages": true
2940
},
3041
"scripts": {
31-
"phpcs8.1": "phpcs --standard=phpcs.ruleset.81.xml src/Example",
32-
"phpcs8.2": "phpcs --standard=phpcs.ruleset.82.xml src/Example",
33-
"phpcs8.3": "phpcs --standard=phpcs.ruleset.83.xml src/Example",
34-
"phpcbf8.1": "phpcbf --standard=phpcs.ruleset.81.xml src/Example",
35-
"phpcbf8.2": "phpcbf --standard=phpcs.ruleset.82.xml src/Example",
36-
"phpcbf8.3": "phpcbf --standard=phpcs.ruleset.83.xml src/Example"
42+
"post-install-cmd": [
43+
"@auto-scripts"
44+
],
45+
"post-update-cmd": [
46+
"@auto-scripts"
47+
],
48+
"auto-scripts": {
49+
"normalizer": "composer normalize"
50+
},
51+
"phpcbf8.1": "phpcbf --standard=phpcs.ruleset.81.xml tests/Example",
52+
"phpcbf8.2": "phpcbf --standard=phpcs.ruleset.82.xml tests/Example",
53+
"phpcbf8.3": "phpcbf --standard=phpcs.ruleset.83.xml tests/Example",
54+
"phpcbf8.4": "phpcbf --standard=phpcs.ruleset.84.xml tests/Example",
55+
"phpcs8.1": "phpcs --standard=phpcs.ruleset.81.xml tests/Example",
56+
"phpcs8.2": "phpcs --standard=phpcs.ruleset.82.xml tests/Example",
57+
"phpcs8.3": "phpcs --standard=phpcs.ruleset.83.xml tests/Example",
58+
"phpcs8.4": "phpcs --standard=phpcs.ruleset.84.xml tests/Example"
3759
}
3860
}

0 commit comments

Comments
 (0)