Skip to content

Commit 38294b4

Browse files
committed
Add PHPCompatibilitySymfonyPolyfillPHP80 ruleset
The Symfony project has released a [polyfill library for PHP 8.0](https://github.com/symfony/polyfill-php80). This adds a corresponding PHPCompatibility ruleset for this polyfill. Includes integration test. Note: not all excludes are "active" yet as by far not all PHP 8.0 features are included in the last PHPCompatibility release (9.3.5). However, these excludes will be "activated" once PHPCompatibility 10.0.0 is released, so we may as well add them already.
1 parent c556de2 commit 38294b4

5 files changed

Lines changed: 74 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ jobs:
5757
diff -B ./PHPCompatibilitySymfonyPolyfillPHP72/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP72/ruleset.xml")
5858
diff -B ./PHPCompatibilitySymfonyPolyfillPHP73/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP73/ruleset.xml")
5959
diff -B ./PHPCompatibilitySymfonyPolyfillPHP74/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP74/ruleset.xml")
60+
diff -B ./PHPCompatibilitySymfonyPolyfillPHP80/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP80/ruleset.xml")
6061
6162
test:
6263
needs: xmllint
@@ -89,6 +90,10 @@ jobs:
8990
- name: Conditionally require specific versions of the polyfills
9091
if: ${{ matrix.php == '5.4' }}
9192
run: |
93+
# Remove the PHP 8 polyfill on PHP < 7 as the minimum requirement is PHP 7.1 and the autoloading
94+
# of the polyfill bootstrap file via Composer would generate a parse error, blocking the DealerDirect plugin
95+
# from setting the installed_paths for PHPCS.
96+
composer remove --dev symfony/polyfill-php80 --no-update --no-scripts
9297
composer require --no-update symfony/polyfill-php72:"1.19" symfony/polyfill-php73:"1.19" symfony/polyfill-php74:"1.19"
9398
9499
- name: Conditionally update PHPCompatibility to develop version
@@ -117,6 +122,12 @@ jobs:
117122
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP73Test.php --standard=PHPCompatibilitySymfonyPolyfillPHP73 --runtime-set testVersion 5.3-
118123
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP74Test.php --standard=PHPCompatibilitySymfonyPolyfillPHP74 --runtime-set testVersion 5.3-
119124
125+
- name: Test the PHP 8.0 ruleset
126+
# The PHP 8.0 polyfill has a minimum PHP requirement of PHP 7.1.
127+
if: ${{ matrix.php != '5.4' }}
128+
run: |
129+
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP80Test.php --standard=PHPCompatibilitySymfonyPolyfillPHP80 --runtime-set testVersion 7.1-
130+
120131
# Check that the rulesets don't throw unnecessary errors for the compat libraries themselves.
121132
# Note: the polyfills for PHP 5.4 - 7.1 have been decoupled from the monorepo at version 1.19.
122133
# and are no longer updated.
@@ -143,3 +154,5 @@ jobs:
143154
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php72/ --standard=PHPCompatibilitySymfonyPolyfillPHP72 --runtime-set testVersion 7.1-
144155
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php73/ --standard=PHPCompatibilitySymfonyPolyfillPHP73 --runtime-set testVersion 7.1-
145156
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php74/ --standard=PHPCompatibilitySymfonyPolyfillPHP74 --runtime-set testVersion 7.1-
157+
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php80/ --standard=PHPCompatibilitySymfonyPolyfillPHP80 --runtime-set testVersion 7.1-
158+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="PHPCompatibilitySymfonyPolyfillPHP80">
3+
<description>PHPCompatibility ruleset for PHP_CodeSniffer which accounts for polyfills provided by the Symfony PHP 8.0 library.</description>
4+
5+
<rule ref="PHPCompatibility">
6+
<!-- https://github.com/symfony/polyfill-php80/blob/master/bootstrap.php -->
7+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.fdivFound"/>
8+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.get_resource_idFound"/>
9+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.preg_last_error_msgFound"/>
10+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.str_containsFound"/>
11+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.str_ends_withFound"/>
12+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.str_starts_withFound"/>
13+
<exclude name="PHPCompatibility.Constants.NewConstants.filter_validate_boolFound"/>
14+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.get_debug_typeFound"/>
15+
16+
<!-- https://github.com/symfony/polyfill-php80/tree/master/Resources/stubs -->
17+
<exclude name="PHPCompatibility.Interfaces.NewInterfaces.stringableFound"/>
18+
<exclude name="PHPCompatibility.Classes.NewClasses.attributeFound"/>
19+
<exclude name="PHPCompatibility.Classes.NewClasses.unhandledmatcherrorFound"/>
20+
<exclude name="PHPCompatibility.Classes.NewClasses.valueerrorFound"/>
21+
</rule>
22+
23+
</ruleset>

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Symfony Polyfill Library | Corresponding PHPCompatibility Ruleset | Includes
2424
[`polyfill-php72`](https://github.com/symfony/polyfill-php72) | `PHPCompatibilitySymfonyPolyfillPHP72` |
2525
[`polyfill-php73`](https://github.com/symfony/polyfill-php73) | `PHPCompatibilitySymfonyPolyfillPHP73` |
2626
[`polyfill-php74`](https://github.com/symfony/polyfill-php74) | `PHPCompatibilitySymfonyPolyfillPHP74` |
27+
[`polyfill-php80`](https://github.com/symfony/polyfill-php80) | `PHPCompatibilitySymfonyPolyfillPHP80` |
2728

2829
> About "Includes":
2930
> Some polyfills have other polyfills as dependencies. If the PHPCompatibility project offers a dedicated ruleset for the polyfill dependency, that ruleset will be included in the ruleset for the higher level polyfill.
@@ -82,6 +83,7 @@ Now you can use the following commands to inspect the code in your project for P
8283
./vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP72
8384
./vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP73
8485
./vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP74
86+
./vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP80
8587

8688
# You can also combine the standards if your project uses several:
8789
./vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP55,PHPCompatibilitySymfonyPolyfillPHP70,PHPCompatibilitySymfonyPolyfillPHP73

Test/SymfonyPolyfillPHP80Test.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/*
3+
* Test file to run PHP_CodeSniffer against to make sure the polyfills are correctly excluded.
4+
*/
5+
6+
class Foo implements Stringable {}
7+
8+
$fdiv = fdiv(10, 3);
9+
10+
try {
11+
$chars = count_chars($string, 5);
12+
} catch(ValueError $e) {
13+
}
14+
15+
$bool = filter_var('yes', FILTER_VALIDATE_BOOL);
16+
17+
$debug = get_debug_type($bar);
18+
19+
if (preg_last_error_msg() !== 'No error') {
20+
exit;
21+
}
22+
23+
if (str_contains($haystack, $needle)) {}
24+
if (str_starts_with($haystack, $needle)) {}
25+
if (str_ends_with($haystack, $needle)) {}
26+
27+
$id = get_resource_id($res);
28+
29+
try {
30+
// Match expression.
31+
} catch(UnhandledMatchError $e) {
32+
}
33+
34+
class MyAttributes extends \Attribute {}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"symfony/polyfill-php71": "1.19",
3232
"symfony/polyfill-php72": "dev-main",
3333
"symfony/polyfill-php73": "dev-main",
34-
"symfony/polyfill-php74": "dev-main"
34+
"symfony/polyfill-php74": "dev-main",
35+
"symfony/polyfill-php80": "dev-main"
3536
},
3637
"suggest" : {
3738
"dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.",

0 commit comments

Comments
 (0)