Skip to content

Commit 5b5d9b4

Browse files
authored
Merge pull request #66 from PHPCompatibility/feature/new-php81-polyfill-ruleset
Add `PHPCompatibilitySymfonyPolyfillPHP81` ruleset
2 parents 69d23c0 + 35ac8c2 commit 5b5d9b4

File tree

5 files changed

+54
-7
lines changed

5 files changed

+54
-7
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ jobs:
6060
diff -B ./PHPCompatibilitySymfonyPolyfillPHP73/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP73/ruleset.xml")
6161
diff -B ./PHPCompatibilitySymfonyPolyfillPHP74/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP74/ruleset.xml")
6262
diff -B ./PHPCompatibilitySymfonyPolyfillPHP80/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP80/ruleset.xml")
63+
diff -B ./PHPCompatibilitySymfonyPolyfillPHP81/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP81/ruleset.xml")
6364
6465
test:
6566
# Don't run the cron job on forks.
@@ -105,16 +106,16 @@ jobs:
105106
- name: "Conditionally require specific versions of the polyfills (PHP 5.4)"
106107
if: ${{ matrix.php == '5.4' }}
107108
run: |
108-
# Remove the PHP 8 polyfill on PHP < 7 as the minimum requirement is PHP 7.1 and the autoloading
109+
# Remove the PHP 8.x polyfills on PHP < 7 as the minimum requirement is PHP 7.1 and the autoloading
109110
# of the polyfill bootstrap file via Composer would generate a parse error, blocking the DealerDirect plugin
110111
# from setting the installed_paths for PHPCS.
111-
composer remove --dev symfony/polyfill-php80 --no-update --no-scripts --no-interaction
112+
composer remove --dev symfony/polyfill-php80 symfony/polyfill-php81 --no-update --no-scripts --no-interaction
112113
composer require --no-update symfony/polyfill-php72:"1.19" symfony/polyfill-php73:"1.19" symfony/polyfill-php74:"1.19" --no-interaction
113114
114115
- name: "Conditionally require specific versions of the polyfills (PHP 7.1)"
115116
if: ${{ matrix.php == '7.1' }}
116117
run: |
117-
composer require --no-update symfony/polyfill-php73:"1.30" symfony/polyfill-php74:"1.30" symfony/polyfill-php80:"1.30" --no-interaction
118+
composer require --no-update symfony/polyfill-php73:"1.30" symfony/polyfill-php74:"1.30" symfony/polyfill-php80:"1.30" symfony/polyfill-php81:"1.30" --no-interaction
118119
119120
- name: Conditionally update PHPCompatibility to develop version
120121
if: ${{ matrix.phpcompat != 'stable' }}
@@ -142,11 +143,12 @@ jobs:
142143
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP73Test.php --standard=PHPCompatibilitySymfonyPolyfillPHP73 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 5.3-
143144
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP74Test.php --standard=PHPCompatibilitySymfonyPolyfillPHP74 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 5.3-
144145
145-
- name: Test the PHP 8.0 ruleset
146-
# The PHP 8.0 polyfill has a minimum PHP requirement of PHP 7.1.
146+
- name: Test the PHP 8.x rulesets
147+
# The PHP 8.x polyfills have a minimum PHP requirement of PHP 7.1.
147148
if: ${{ matrix.php != '5.4' }}
148149
run: |
149-
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP80Test.php --exclude=PHPCompatibility.Upgrade.LowPHP --standard=PHPCompatibilitySymfonyPolyfillPHP80 --runtime-set testVersion 7.1-
150+
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP80Test.php --standard=PHPCompatibilitySymfonyPolyfillPHP80 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
151+
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP81Test.php --standard=PHPCompatibilitySymfonyPolyfillPHP81 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
150152
151153
# Check that the rulesets don't throw unnecessary errors for the compat libraries themselves.
152154
# Note: the polyfills for PHP 5.4 - 7.1 have been decoupled from the monorepo at version 1.19.
@@ -176,6 +178,7 @@ jobs:
176178
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php73/ --standard=PHPCompatibilitySymfonyPolyfillPHP73 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
177179
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php74/ --standard=PHPCompatibilitySymfonyPolyfillPHP74 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
178180
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php80/ --standard=PHPCompatibilitySymfonyPolyfillPHP80 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
181+
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php81/ --standard=PHPCompatibilitySymfonyPolyfillPHP81 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
179182
180183
# The polyfills for PHP 7.3 and higher are compatible with PHP 7.2+ at the current version.
181184
- name: "Test running against the polyfills - polyfills 7.3- (current)"
@@ -184,3 +187,4 @@ jobs:
184187
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php73/ --standard=PHPCompatibilitySymfonyPolyfillPHP73 --runtime-set testVersion 7.2-
185188
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php74/ --standard=PHPCompatibilitySymfonyPolyfillPHP74 --runtime-set testVersion 7.2-
186189
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php80/ --standard=PHPCompatibilitySymfonyPolyfillPHP80 --runtime-set testVersion 7.2-
190+
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php81/ --standard=PHPCompatibilitySymfonyPolyfillPHP81 --runtime-set testVersion 7.2-
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHPCompatibilitySymfonyPolyfillPHP81" xsi:noNamespaceSchemaLocation="https://schema.phpcodesniffer.com/phpcs.xsd">
3+
4+
<description>PHPCompatibility ruleset for PHP_CodeSniffer which accounts for polyfills provided by the Symfony PHP 8.1 library.</description>
5+
6+
<rule ref="PHPCompatibility">
7+
<!-- https://github.com/symfony/polyfill-php81/blob/main/bootstrap.php -->
8+
<exclude name="PHPCompatibility.Constants.NewConstants.mysqli_refresh_replicaFound"/>
9+
<exclude name="PHPCompatibility.Constants.RemovedConstants.mysqli_refresh_replicaDeprecated"/>
10+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.array_is_listFound"/>
11+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.enum_existsFound"/>
12+
13+
<!-- https://github.com/symfony/polyfill-php81/tree/main/Resources/stubs -->
14+
<exclude name="PHPCompatibility.Classes.NewClasses.curlstringfileFound"/>
15+
</rule>
16+
17+
<!-- Prevent false positives being thrown when run over the code of polyfill-php81 itself. -->
18+
<rule ref="PHPCompatibility.Classes.NewClasses.attributeFound">
19+
<exclude-pattern>/polyfill-php81/Resources/stubs/ReturnTypeWillChange\.php$</exclude-pattern>
20+
</rule>
21+
<rule ref="PHPCompatibility.Attributes.NewAttributes.PHPNativeAttributeFound">
22+
<exclude-pattern>/polyfill-php81/Resources/stubs/ReturnTypeWillChange\.php$</exclude-pattern>
23+
</rule>
24+
25+
</ruleset>

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ These rulesets prevent false positives from the [PHPCompatibility standard][PHPC
2525
| [`polyfill-php73`] | `PHPCompatibilitySymfonyPolyfillPHP73` | |
2626
| [`polyfill-php74`] | `PHPCompatibilitySymfonyPolyfillPHP74` | |
2727
| [`polyfill-php80`] | `PHPCompatibilitySymfonyPolyfillPHP80` | |
28+
| [`polyfill-php81`] | `PHPCompatibilitySymfonyPolyfillPHP81` | |
2829

2930
> [!NOTE]
3031
> About "Includes":
@@ -97,6 +98,7 @@ vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP72
9798
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP73
9899
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP74
99100
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP80
101+
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP81
100102

101103
# You can also combine the standards if your project uses several:
102104
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP55,PHPCompatibilitySymfonyPolyfillPHP70,PHPCompatibilitySymfonyPolyfillPHP73
@@ -150,3 +152,4 @@ All code within the PHPCompatibility organisation is released under the GNU Less
150152
[`polyfill-php73`]: https://github.com/symfony/polyfill-php73
151153
[`polyfill-php74`]: https://github.com/symfony/polyfill-php74
152154
[`polyfill-php80`]: https://github.com/symfony/polyfill-php80
155+
[`polyfill-php81`]: https://github.com/symfony/polyfill-php81

Test/SymfonyPolyfillPHP81Test.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/*
3+
* Test file to run PHP_CodeSniffer against to make sure the polyfills are correctly excluded.
4+
*/
5+
6+
if (array_is_list($array) === true) {}
7+
8+
$exists = enum_exists(name::class);
9+
10+
echo MYSQLI_REFRESH_REPLICA;
11+
12+
class Foo extends ReturnTypeWillChange {}
13+
14+
$file = new CURLStringFile();

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
"symfony/polyfill-php72": "1.30",
3939
"symfony/polyfill-php73": "1.x-dev",
4040
"symfony/polyfill-php74": "1.x-dev",
41-
"symfony/polyfill-php80": "1.x-dev"
41+
"symfony/polyfill-php80": "1.x-dev",
42+
"symfony/polyfill-php81": "1.x-dev"
4243
},
4344
"prefer-stable" : true
4445
}

0 commit comments

Comments
 (0)