Skip to content

Commit 45f25c7

Browse files
authored
Merge pull request #32 from YouweGit/feature/v3-ruleset-changes
chore: update rulesets content, structure and loading strategy
2 parents d1e64b5 + 534359b commit 45f25c7

Some content is hidden

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

53 files changed

+427
-412
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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
```bash
11+
composer require --dev youwe/testing-suite:^3.0 --no-update
12+
composer remove --dev youwe/coding-standard youwe/coding-standard-magento2 --no-update
13+
composer update youwe/testing-suite -W
14+
composer install
15+
```
16+
17+
Note: starting v3, phpunit may be installed in your project automatically.\
18+
We use the @stable version constraint for this. If you want to install a specific
19+
phpunit version in your project you are free to do so. Upstream phpunit versions
20+
are honored during installation.
21+
22+
### 3. Sanity checks
23+
Check the following
24+
25+
1. The PHPCS file exists in your project root and points to the correct ruleset
26+
configuration in youwe/testing-suite
27+
2. The PHPMD file exists in your project root and points to the correct ruleset
28+
configuration in youwe/testing-suite
29+
3. Run `ddev exec grumphp run` or `vendor/bin/grumphp run`
30+
4. Your git commit hook still functions as expected
31+
32+
### 4. Refactor and/or update/regenerate exclusion rules
33+
Some rulesets will have changed. In a general sense, the rulesets are less
34+
strict compared to what they were before.
35+
36+
If your grumphp tasks are failing due to changes in rulesets, you have 3 options:
37+
38+
1. Refactor. This is always the preferred route if the amount of issues raised
39+
is limited.
40+
2. Add exclusion filters. Use existing tooling or update your project configuration
41+
files to exclude existing project files. This will help in the short-term. Note
42+
that it is always recommended to still refactor in the future so the file
43+
exclusions lists will reduce in size over time.
44+
3. Update rulesets in your project. Projects are free to update rulesets and
45+
validation if they want. Of course it is always recommended to add
46+
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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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>Default / Fallback configuration for PHPMD rulesets.</description>
7+
8+
<!-- Taken from Global ruleset since we can't modify a referenced rule without overwriting it completely.
9+
See: https://github.com/phpmd/phpmd/issues/39 -->
10+
<rule ref="rulesets/cleancode.xml">
11+
<!-- Even though else statements can be rewritten to be avoided, this rule to always block else statements is a bit
12+
extreme to enforce in standards. Rule can still be adopted on project-level if needed. -->
13+
<exclude name="ElseExpression"/>
14+
<!-- We should not assume all code is OOP based, and static usage is not inherently bad outside OOP/SOLID contexts. -->
15+
<exclude name="StaticAccess"/>
16+
<!-- Boolean flags are sometimes needed to preserve e.g. backwards compatibility. We don't want to enforce this in a blanket
17+
statement / default rule but if projects want to enforce this they are free to do so. -->
18+
<exclude name="BooleanArgumentFlag"/>
19+
</rule>
20+
21+
<rule ref="rulesets/codesize.xml" />
22+
<rule ref="rulesets/design.xml" />
23+
<rule ref="rulesets/unusedcode.xml" />
24+
<rule ref="rulesets/naming.xml" />
25+
26+
<rule ref="rulesets/naming.xml/LongVariable">
27+
<properties>
28+
<!-- 20 limit is hard to make descriptive, plus has historically been 30 so also for better backwards compatibility support -->
29+
<property name="maximum" value="30"/>
30+
</properties>
31+
</rule>
32+
<!-- End of global ruleset -->
33+
</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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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>PHPMD rules for Drupal projects.</description>
7+
<rule ref="./config/default/phpmd.xml" />
8+
9+
<!-- No overrides compared to default. Revisit this file and recreate default drupal rulesets for projects if needed.
10+
Note: seperate ruleset needed until https://github.com/phpmd/phpmd/issues/39 is resolved -->
11+
</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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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>PHPMD rules for Magento 2 projects.</description>
7+
8+
<!-- Taken from Global ruleset since we can't modify a referenced rule without overwriting it completely.
9+
See: https://github.com/phpmd/phpmd/issues/39 -->
10+
<rule ref="rulesets/cleancode.xml">
11+
<!-- Even though else statements can be rewritten to be avoided, this rule to always block else statements is a bit
12+
extreme to enforce in standards. Rule can still be adopted on project-level if needed. -->
13+
<exclude name="ElseExpression"/>
14+
<!-- We should not assume all code is OOP based, and static usage is not inherently bad outside OOP/SOLID contexts. -->
15+
<exclude name="StaticAccess"/>
16+
<!-- Boolean flags are sometimes needed to preserve e.g. backwards compatibility. We don't want to enforce this in a blanket
17+
statement / default rule but if projects want to enforce this they are free to do so. -->
18+
<exclude name="BooleanArgumentFlag"/>
19+
</rule>
20+
21+
<rule ref="rulesets/codesize.xml" />
22+
<rule ref="rulesets/design.xml" />
23+
<rule ref="rulesets/unusedcode.xml" />
24+
<rule ref="rulesets/naming.xml" />
25+
26+
<rule ref="rulesets/naming.xml/LongVariable">
27+
<properties>
28+
<!-- 20 limit is hard to make descriptive, plus has historically been 30 so also for better backwards compatibility support -->
29+
<property name="maximum" value="30"/>
30+
</properties>
31+
</rule>
32+
<!-- End of global ruleset -->
33+
34+
<!-- Increase maximum amount of coupling, because magento constructor injection can become quite extreme and is mostly an adobe issue to fix -->
35+
<rule ref="rulesets/design.xml">
36+
<exclude name="CouplingBetweenObjects"/>
37+
</rule>
38+
39+
<rule ref="rulesets/design.xml/CouplingBetweenObjects">
40+
<properties>
41+
<property name="maximum" value="20"/>
42+
</properties>
43+
</rule>
44+
45+
</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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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>PHPMD rules for Pimcore projects.</description>
7+
8+
<!-- Taken from Global ruleset since we can't modify a referenced rule without overwriting it completely.
9+
See: https://github.com/phpmd/phpmd/issues/39 -->
10+
<rule ref="rulesets/cleancode.xml">
11+
<!-- Even though else statements can be rewritten to be avoided, this rule to always block else statements is a bit
12+
extreme to enforce in standards. Rule can still be adopted on project-level if needed. -->
13+
<exclude name="ElseExpression"/>
14+
<!-- We should not assume all code is OOP based, and static usage is not inherently bad outside OOP/SOLID contexts. -->
15+
<exclude name="StaticAccess"/>
16+
<!-- Boolean flags are sometimes needed to preserve e.g. backwards compatibility. We don't want to enforce this in a blanket
17+
statement / default rule but if projects want to enforce this they are free to do so. -->
18+
<exclude name="BooleanArgumentFlag"/>
19+
</rule>
20+
21+
<rule ref="rulesets/codesize.xml" />
22+
<rule ref="rulesets/design.xml" />
23+
<rule ref="rulesets/unusedcode.xml" />
24+
<rule ref="rulesets/naming.xml" />
25+
26+
<rule ref="rulesets/naming.xml/LongVariable">
27+
<properties>
28+
<!-- 20 limit is hard to make descriptive, plus has historically been 30 so also for better backwards compatibility support -->
29+
<property name="maximum" value="30"/>
30+
</properties>
31+
</rule>
32+
<!-- End of global ruleset -->
33+
34+
<!-- up() is required for doctrine migrations when implementing the interface. -->
35+
<rule ref="rulesets/naming.xml/ShortMethodName">
36+
<properties>
37+
<property name="exceptions" value="up" />
38+
</properties>
39+
</rule>
40+
</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

docs/examples/github-actions.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
11
# GitHub Actions
22

3-
The example below will run the testing-suite inside [github actions] (https://github.com/features/actions)
4-
for both PHP 7.4 and 8.1.
3+
The example below will run the testing-suite inside [github actions](https://github.com/features/actions)
4+
for PHP versions 8.1 through 8.4 and specify whether PHPUnit should also be run depending on PHP version.
55

66
```yml
77
name: Testing Suite
88
on: [push]
99
jobs:
1010
PHP:
1111
strategy:
12-
# Test with multiple PHP versions
1312
matrix:
14-
image: [
15-
'srcoder/development-php:php74-fpm',
16-
'srcoder/development-php:php81-fpm'
17-
]
13+
php-version: [8.1, 8.2, 8.3, 8.4]
1814
runs-on: ubuntu-latest
1915
container:
20-
image: ${{ matrix.image }}
16+
image: ${{ matrix.php-version == '8.1' && 'srcoder/development-php:php81-fpm' ||
17+
matrix.php-version == '8.2' && 'srcoder/development-php:php82-fpm' ||
18+
matrix.php-version == '8.3' && 'srcoder/development-php:php83-fpm' ||
19+
matrix.php-version == '8.4' && 'srcoder/development-php:php84-fpm' }}
2120
steps:
22-
# Checkout the repository
2321
- name: Checkout
2422
uses: actions/checkout@v2
25-
# Run Testing Suite
26-
- name: Testing Suite
23+
24+
- name: Install Dependencies
2725
run: |
2826
composer2 install --dev --prefer-dist --no-scripts --no-progress --optimize-autoloader --no-interaction -vvv
2927
composer2 show
30-
composer2 exec -v grumphp run
3128
shell: bash
3229

30+
- name: Run GrumPHP Tasks
31+
run: |
32+
if [[ "${{ matrix.php-version }}" == "8.1" || "${{ matrix.php-version }}" == "8.2" ]]; then
33+
composer2 exec -v grumphp -- run --tasks=composer,jsonlint,xmllint,yamllint,phpcs,phplint,phpmd,phpstan,securitychecker_enlightn
34+
else
35+
composer2 exec -v grumphp -- run
36+
fi
37+
shell: bash
38+
39+
3340
```

0 commit comments

Comments
 (0)