Skip to content

Commit 6265a3b

Browse files
author
Stefan Boonstra
committed
chore: update rulesets content, structure and loading strategy
* Move rulesets from additional dependencies to testing-suite * This will reduce overhead and make it easier to maintain * Refresh PHPCS rulesets * Refresh PHPMD rulesets * Drop support for Laravel and Magento 1 * Add initial supporting structure for Drupal * Drop youwe/coding-standard-phpstorm dependency and add as suggest * Add documentation changes * Refactor testing suite implementation to conform to new rulesets
1 parent d1e64b5 commit 6265a3b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+437
-324
lines changed

CHANGELOG.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
### Added
99
- Added `phpunit/phpunit` to suggested dependencies in `composer.json`.
1010
- Added `youwe/coding-standard-phpstorm` to suggested dependencies in `composer.json`.
11-
- Added support to honor upstream version constraints
11+
- Added support to honor upstream version constraints.
1212
- Github action for php 8.3 and php 8.4 to run unit tests against PHPUnit 12.
13-
- Testing suite now attempts to install phpunit upstream if it isn't available yet
14-
- Existing upstream versions are honored if already installed
15-
- Upstream projects not having phpunit installed will install phpunit with an @stable version
13+
- Testing suite now attempts to install phpunit upstream if it isn't available yet.
14+
- Existing upstream versions are honored if already installed.
15+
- Upstream projects not having phpunit installed will install phpunit with an @stable version.
16+
- Added support for Drupal configuration and templates.
17+
- Migration docs for migration from v2 to v3 of the testing suite.
1618

1719
### Changed
18-
- Unit tests as part of the testing suite are rewritten for PHPUnit 12
19-
- Updated GitHub Action workflows to support PHP 8.1, 8.2, and 8.3.
20+
- Unit tests as part of the testing suite are rewritten for PHPUnit 12.
21+
- Updated GitHub Action workflows to support PHP 8.1, 8.2, 8.3, and 8.4
2022
- `composer.json`: Dropped support for PHP < 8.1.
21-
- Moved phpunit from require to require-dev
23+
- Moved phpunit from require to require-dev.
2224
- Changed PHPMD suppressions in docblocks to quote the rule name, due to changes in later versions of PHPStan that create false positives on these docblocks if not quoted.
25+
- Moved existing project-type specific rulesets from inner dependencies to testing-suite package.
26+
- Simplified PHPMD rulesets with rationale behind rule changes.
27+
- Updated remote schema location URL for phpmd rulesets to prevent redirecting which may cause flaky builds.
2328

2429
### Removed
2530
- Removed support for EOL PHP versions. Projects running PHP < 8.1 can stick to version 2 of the testing-suite.
2631
- Removed support for Composer 1. Projects still relying on Composer 1 can stick to version 2 of the testing-suite.
27-
- Removed `youwe/coding-standard-phpstorm` as dependency (it is still listed in suggest)
28-
- Removed `phpunit/phpunit` as direct dependency (it is still in require-dev and installed upstream through the `youwe/dependency-installer`)
29-
- Github actions for php < 8.1
32+
- Removed `youwe/coding-standard-phpstorm` as dependency (it is still listed in suggest).
33+
- Removed `phpunit/phpunit` as direct dependency (it is still in require-dev and installed upstream through the `youwe/dependency-installer`).
34+
- Github actions for php < 8.1.
35+
- Dependency on seperated coding style packages to simplify development and remove overhead.
36+
- Dropped support for Laravel and Magento 1.
37+
- Dropped inner dependencies on coding-standard, coding-standard-magento2, and coding-standard-phpstorm packages.
3038

3139
## 2.19.1
3240
### Changed
@@ -126,7 +134,7 @@ on functions ending with `add()` or `odd()` due to checks on dump and die `dd()`
126134
## 2.12 - 2022-05-30
127135
### Added
128136
- PHP 8 compatibility.
129-
- GitHub Actions Workflow to run testing-suite for PHP 7.4, 8.0 and 8.1.
137+
- GitHub Actions Workflow to run testing-suite for PHP 7.4, 8.0, and 8.1.
130138

131139
## 2.11.1 - 2022-04-10
132140
### Changed

MIGRATION.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
## Testing suite v2 to v3 migration guide
2+
TODO: Validate / update / rewrite this based on experience and later changes when adding the testing suite
3+
based on experiences with initial v3.0.0-rc1 tests.
4+
5+
### 1. Double check your project type in the project composer.json.
6+
We use the project type to automatically update some ruleset mappings for PHPCS and PHPMD.
7+
8+
For a list of supported project types, see the [readme](./README.md).
9+
### 2. Update to version 3
10+
When using ddev:
11+
```bash
12+
ddev composer require --dev youwe/testing-suite:^3.0 --no-update
13+
ddev composer remove --dev youwe/coding-standard youwe/coding-standard-magento2 --no-update
14+
ddev composer update youwe/testing-suite -W
15+
ddev composer install
16+
```
17+
18+
When not using ddev:
19+
```text
20+
Same as above but using local composer installation (not-recommended)
21+
```
22+
23+
### 3. Sanity checks
24+
Check the following
25+
26+
1. The PHPCS file exists in your project root and points to the correct ruleset
27+
configuration in youwe/testing-suite
28+
2. The PHPMD file exists in your project root and points to the correct ruleset
29+
configuration in youwe/testing-suite
30+
3. Run `ddev exec grumphp run` or `vendor/bin/grumphp run`
31+
4. Your git commit hook still functions as expected
32+
33+
### 4. Refactor and/or update/regenerate exclusion rules
34+
Some rulesets will have changed. In a general sense, the rulesets are less
35+
strict compared to what they were before.
36+
37+
If your grumphp tasks are failing due to changes in rulesets, you have 3 options:
38+
39+
1. Refactor. This is always the preferred route if the amount of issues raised
40+
is limited.
41+
2. Add exclusion filters. Use existing tooling or update your project configuration
42+
files to exclude existing project files. This will help in the short-term. Note
43+
that it is always recommended to still refactor in the future so the file
44+
exclusions lists will reduce in size over time.
45+
3. Update rulesets in your project. Projects are free to update rulesets and
46+
validation if they want. Of course it is always recommended to add
47+
additional rules instead of removing existing rules.

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@ predefined default configurations per project type.
1111

1212
## Features
1313

14-
- [Project Type detector](docs/features/project-type-detector.md)
14+
- [Project Type detector](docs/features/project-type-detection.md)
1515
- [PHP storm configuration](docs/features/php-storm-integration.md)
1616

1717
## Supported project types
1818

1919
- Default (`default`)
20-
- Laravel (`laravel`)
21-
- [Magento 1](docs/project-types/magento1.md) (`magento1`)
2220
- [Magento 2](docs/project-types/magento2.md) (`magento2`)
2321
- Pimcore (`pimcore`)
22+
- Drupal (`drupal`)
2423

2524
## Included analysis tools
2625

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@
2626
"require": {
2727
"php": "^8.1",
2828
"composer-plugin-api": "^2.0",
29+
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
2930
"enlightn/security-checker": "^1.5 || ^2.0",
3031
"kint-php/kint": "@stable",
3132
"php-parallel-lint/php-parallel-lint": "^1.2",
33+
"phpmd/phpmd": "^2.15",
3234
"phpro/grumphp-shim": "^1.13",
3335
"phpstan/phpstan": "@stable",
34-
"youwe/coding-standard": "^3.5.0",
36+
"squizlabs/php_codesniffer": "^3.12.0",
3537
"youwe/composer-dependency-installer": "^1.4.0",
3638
"youwe/composer-file-installer": "^1.2.0"
3739
},

config/default/phpmd.xml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Youwe/Global"
3+
xmlns="http://pmd.sf.net/ruleset/1.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 https://pmd.sourceforge.io/ruleset_xml_schema.xsd">
6+
<description>
7+
Global defined PHPMD rules
8+
</description>
9+
10+
<!-- Taken from Global ruleset since we can't modify a referenced rule without overwriting it completely.
11+
See: https://github.com/phpmd/phpmd/issues/39 -->
12+
<rule ref="rulesets/cleancode.xml">
13+
<!-- Even though else statements can be rewritten to be avoided, this rule to always block else statements is a bit
14+
extreme to enforce in standards. Rule can still be adopted on project-level if needed. -->
15+
<exclude name="ElseExpression"/>
16+
<!-- We should not assume all code is OOP based, and static usage is not inherently bad outside OOP/SOLID contexts. -->
17+
<exclude name="StaticAccess"/>
18+
<!-- Boolean flags are sometimes needed to preserve e.g. backwards compatibility. We don't want to enforce this in a blanket
19+
statement / default rule but if projects want to enforce this they are free to do so. -->
20+
<exclude name="BooleanArgumentFlag"/>
21+
</rule>
22+
23+
<rule ref="rulesets/codesize.xml" />
24+
<rule ref="rulesets/design.xml" />
25+
<rule ref="rulesets/unusedcode.xml" />
26+
<rule ref="rulesets/naming.xml" />
27+
28+
<rule ref="rulesets/naming.xml/LongVariable">
29+
<properties>
30+
<!-- 20 limit is hard to make descriptive, plus has historically been 30 so also for better backwards compatibility support -->
31+
<property name="maximum" value="30"/>
32+
</properties>
33+
</rule>
34+
<!-- End of global ruleset -->
35+
</ruleset>

config/default/ruleset.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Youwe/Default">
3+
<description>Youwe coding standards for code sniffing for generic platform-agnostic PHP code.</description>
4+
<!-- Show sniff codes in all reports. Easier to ignore rules when necessary -->
5+
<arg value="s"/>
6+
<!-- Use colors in output -->
7+
<arg name="colors" />
8+
9+
<!-- Base rules on PSR12 -->
10+
<rule ref="PSR12" />
11+
</ruleset>

config/drupal/grumphp.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
imports:
2+
- resource: '../default/grumphp.yml'
3+
4+
# Extend git triggers with common Drupal constructs
5+
parameters:
6+
git_blacklist.triggered_by: [ 'php', 'js', 'twig' ]

config/drupal/phpmd.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="PHPMD"
3+
xmlns="http://pmd.sf.net/ruleset/1.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 https://pmd.sourceforge.io/ruleset_xml_schema.xsd">
6+
<description>
7+
Global defined PHPMD rules for Drupal projects
8+
</description>
9+
<rule ref="./config/default/phpmd.xml" />
10+
11+
<!-- No overrides compared to default. Revisit this file and recreate default drupal rulesets for projects if needed.
12+
Note: seperate ruleset needed until https://github.com/phpmd/phpmd/issues/39 is resolved -->
13+
</ruleset>

config/drupal/ruleset.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Youwe/Drupal">
3+
<description>Youwe coding standard extensions for sniffing code in Drupal projects.</description>
4+
5+
<!-- Use default Youwe coding standards for PHP projects. -->
6+
<rule ref="../default" />
7+
<!-- Additional Drupal-specific rulesets. -->
8+
9+
</ruleset>

config/magento2/phpmd.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="PHPMD"
3+
xmlns="http://pmd.sf.net/ruleset/1.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 https://pmd.sourceforge.io/ruleset_xml_schema.xsd">
6+
<description>
7+
Global defined PHPMD rules for Magento 2 projects
8+
</description>
9+
10+
<!-- Taken from Global ruleset since we can't modify a referenced rule without overwriting it completely.
11+
See: https://github.com/phpmd/phpmd/issues/39 -->
12+
<rule ref="rulesets/cleancode.xml">
13+
<!-- Even though else statements can be rewritten to be avoided, this rule to always block else statements is a bit
14+
extreme to enforce in standards. Rule can still be adopted on project-level if needed. -->
15+
<exclude name="ElseExpression"/>
16+
<!-- We should not assume all code is OOP based, and static usage is not inherently bad outside OOP/SOLID contexts. -->
17+
<exclude name="StaticAccess"/>
18+
<!-- Boolean flags are sometimes needed to preserve e.g. backwards compatibility. We don't want to enforce this in a blanket
19+
statement / default rule but if projects want to enforce this they are free to do so. -->
20+
<exclude name="BooleanArgumentFlag"/>
21+
</rule>
22+
23+
<rule ref="rulesets/codesize.xml" />
24+
<rule ref="rulesets/design.xml" />
25+
<rule ref="rulesets/unusedcode.xml" />
26+
<rule ref="rulesets/naming.xml" />
27+
28+
<rule ref="rulesets/naming.xml/LongVariable">
29+
<properties>
30+
<!-- 20 limit is hard to make descriptive, plus has historically been 30 so also for better backwards compatibility support -->
31+
<property name="maximum" value="30"/>
32+
</properties>
33+
</rule>
34+
<!-- End of global ruleset -->
35+
36+
<!-- Increase maximum amount of coupling, because magento constructor injection can become quite extreme and is mostly an adobe issue to fix -->
37+
<rule ref="rulesets/design.xml">
38+
<exclude name="CouplingBetweenObjects"/>
39+
</rule>
40+
41+
<rule ref="rulesets/design.xml/CouplingBetweenObjects">
42+
<properties>
43+
<property name="maximum" value="20"/>
44+
</properties>
45+
</rule>
46+
47+
</ruleset>

config/magento2/ruleset.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Youwe/Magento2">
3+
<description>Youwe coding standard extensions for sniffing code in Magento 2 projects.</description>
4+
5+
<!-- Use default Youwe coding standards for PHP projects. -->
6+
<rule ref="../default" />
7+
<!-- Magento coding standards -->
8+
<rule ref="Magento2" />
9+
</ruleset>

config/pimcore/phpmd.xml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="PHPMD"
3+
xmlns="https://pmd.sf.net/ruleset/1.0.0"
4+
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 https://pmd.sourceforge.io/ruleset_xml_schema.xsd">
6+
<description>
7+
Global defined PHPMD rules for Pimcore projects
8+
</description>
9+
10+
<!-- Taken from Global ruleset since we can't modify a referenced rule without overwriting it completely.
11+
See: https://github.com/phpmd/phpmd/issues/39 -->
12+
<rule ref="rulesets/cleancode.xml">
13+
<!-- Even though else statements can be rewritten to be avoided, this rule to always block else statements is a bit
14+
extreme to enforce in standards. Rule can still be adopted on project-level if needed. -->
15+
<exclude name="ElseExpression"/>
16+
<!-- We should not assume all code is OOP based, and static usage is not inherently bad outside OOP/SOLID contexts. -->
17+
<exclude name="StaticAccess"/>
18+
<!-- Boolean flags are sometimes needed to preserve e.g. backwards compatibility. We don't want to enforce this in a blanket
19+
statement / default rule but if projects want to enforce this they are free to do so. -->
20+
<exclude name="BooleanArgumentFlag"/>
21+
</rule>
22+
23+
<rule ref="rulesets/codesize.xml" />
24+
<rule ref="rulesets/design.xml" />
25+
<rule ref="rulesets/unusedcode.xml" />
26+
<rule ref="rulesets/naming.xml" />
27+
28+
<rule ref="rulesets/naming.xml/LongVariable">
29+
<properties>
30+
<!-- 20 limit is hard to make descriptive, plus has historically been 30 so also for better backwards compatibility support -->
31+
<property name="maximum" value="30"/>
32+
</properties>
33+
</rule>
34+
<!-- End of global ruleset -->
35+
36+
<!-- up() is required for doctrine migrations when implementing the interface. -->
37+
<rule ref="rulesets/naming.xml/ShortMethodName">
38+
<properties>
39+
<property name="exceptions" value="up" />
40+
</properties>
41+
</rule>
42+
</ruleset>

config/pimcore/ruleset.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Youwe/Pimcore">
3+
<description>Youwe coding standard extensions for sniffing code in Pimcore projects.</description>
4+
5+
<!-- Use default Youwe coding standards for PHP projects. -->
6+
<rule ref="../default" />
7+
8+
<!-- Pimcore specific exclusions -->
9+
<exclude-pattern>*/bin/*</exclude-pattern>
10+
<exclude-pattern>*/install-profiles/*</exclude-pattern>
11+
<exclude-pattern>*/public/*</exclude-pattern>
12+
<exclude-pattern>*/var/*</exclude-pattern>
13+
</ruleset>

docs/components/phpcs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ During the installation of the testing suite a file called `phpcs.xml` is added
77
the root of the repository which refers to the coding standard. To make
88
adjustments to the coding standard this file can be edited and committed.
99

10-
[PHPCS](https://github.com/FriendsOfPHP/PHP-CS-Fixer)
10+
[PHPCS](https://github.com/FriendsOfPHP/PHP-CS-Fixer) \
1111
[PHP Coding Standards Fixer](https://github.com/squizlabs/PHP_CodeSniffer)
1212

1313
## Common issues

0 commit comments

Comments
 (0)