Skip to content

Commit 1314ceb

Browse files
authored
Merge pull request #71 from PHPCompatibility/feature/new-php85-polyfill-ruleset
Add `PHPCompatibilitySymfonyPolyfillPHP85` ruleset
2 parents 49b99f7 + 0c29df7 commit 1314ceb

File tree

5 files changed

+73
-8
lines changed

5 files changed

+73
-8
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ jobs:
6464
diff -B ./PHPCompatibilitySymfonyPolyfillPHP82/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP82/ruleset.xml")
6565
diff -B ./PHPCompatibilitySymfonyPolyfillPHP83/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP83/ruleset.xml")
6666
diff -B ./PHPCompatibilitySymfonyPolyfillPHP84/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP84/ruleset.xml")
67+
diff -B ./PHPCompatibilitySymfonyPolyfillPHP85/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP85/ruleset.xml")
6768
6869
test:
6970
# Don't run the cron job on forks.
@@ -79,7 +80,7 @@ jobs:
7980
# The polyfills need to be installed at v 1.19 (last before the version drop) to test this.
8081
# - As of version v 1.20, the Symfony polyfills support PHP >= 7.1.
8182
# The polyfills need to be installed at v 1.30 (last before the version drop) to test this.
82-
# - As of version v 1.31, the Symfony polyfills support PHP >= 7.2 (tested via "latest").
83+
# - As of version v 1.31, the Symfony polyfills support PHP >= 7.2 (tested via PHP "latest").
8384
# The polyfills should default to the latest release to test this.
8485
php: ['5.4', '7.1', 'latest']
8586
phpcompat: ['stable']
@@ -112,13 +113,15 @@ jobs:
112113
# Remove the PHP 8.x polyfills on PHP < 7 as the minimum requirement is PHP 7.1 and the autoloading
113114
# of the polyfill bootstrap file via Composer would generate a parse error, blocking the DealerDirect plugin
114115
# from setting the installed_paths for PHPCS.
115-
composer remove --dev symfony/polyfill-php80 symfony/polyfill-php81 symfony/polyfill-php82 symfony/polyfill-php83 symfony/polyfill-php84 --no-update --no-scripts --no-interaction
116-
composer require --no-update symfony/polyfill-php72:"1.19" symfony/polyfill-php73:"1.19" symfony/polyfill-php74:"1.19" --no-interaction
116+
composer remove --dev symfony/polyfill-php80 symfony/polyfill-php81 symfony/polyfill-php82 symfony/polyfill-php83 symfony/polyfill-php84 symfony/polyfill-php85 --no-update --no-scripts --no-interaction
117+
composer require --dev --no-update symfony/polyfill-php72:"1.19" symfony/polyfill-php73:"1.19" symfony/polyfill-php74:"1.19" --no-interaction
117118
118119
- name: "Conditionally require specific versions of the polyfills (PHP 7.1)"
119120
if: ${{ matrix.php == '7.1' }}
120121
run: |
121-
composer require --no-update symfony/polyfill-php73:"1.30" symfony/polyfill-php74:"1.30" symfony/polyfill-php80:"1.30" symfony/polyfill-php81:"1.30" symfony/polyfill-php82:"1.30" symfony/polyfill-php83:"1.30" symfony/polyfill-php84:"1.30" --no-interaction
122+
# Remove the PHP >= 8.5 polyfills on PHP 7.1 as the minimum requirement is PHP 7.2.
123+
composer remove --dev symfony/polyfill-php85 --no-update --no-scripts --no-interaction
124+
composer require --dev --no-update symfony/polyfill-php73:"1.30" symfony/polyfill-php74:"1.30" symfony/polyfill-php80:"1.30" symfony/polyfill-php81:"1.30" symfony/polyfill-php82:"1.30" symfony/polyfill-php83:"1.30" symfony/polyfill-php84:"1.30" --no-interaction
122125
123126
- name: Conditionally update PHPCompatibility to develop version
124127
if: ${{ matrix.phpcompat != 'stable' }}
@@ -146,7 +149,7 @@ jobs:
146149
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP73Test.php --standard=PHPCompatibilitySymfonyPolyfillPHP73 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 5.3-
147150
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP74Test.php --standard=PHPCompatibilitySymfonyPolyfillPHP74 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 5.3-
148151
149-
- name: Test the PHP 8.x rulesets
152+
- name: Test the PHP 8.0-8.4 rulesets
150153
# The PHP 8.x polyfills have a minimum PHP requirement of PHP 7.1.
151154
if: ${{ matrix.php != '5.4' }}
152155
run: |
@@ -156,6 +159,12 @@ jobs:
156159
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP83Test.php --standard=PHPCompatibilitySymfonyPolyfillPHP83 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
157160
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP84Test.php --standard=PHPCompatibilitySymfonyPolyfillPHP84 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
158161
162+
- name: Test the PHP 8.5 ruleset
163+
# The PHP 8.5 polyfills have a minimum PHP requirement of PHP 7.2.
164+
if: ${{ matrix.php == 'latest' }}
165+
run: |
166+
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP85Test.php --standard=PHPCompatibilitySymfonyPolyfillPHP85 --runtime-set testVersion 7.2-
167+
159168
# Check that the rulesets don't throw unnecessary errors for the compat libraries themselves.
160169
# Note: the polyfills for PHP 5.4 - 7.1 have been decoupled from the monorepo at version 1.19.
161170
# The polyfills for PHP 7.2 have been decoupled from the monorepo at version 1.30.
@@ -168,15 +177,15 @@ jobs:
168177
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php70/ --standard=PHPCompatibilitySymfonyPolyfillPHP70 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 5.3-
169178
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php71/ --standard=PHPCompatibilitySymfonyPolyfillPHP71 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 5.3-
170179
171-
# The polyfills for PHP 7.2 and higher are compatible with PHP 5.3+ at version 1.19.
180+
# The polyfills for PHP 7.2-7.4 are compatible with PHP 5.3+ at version 1.19.
172181
- name: "Test running against the polyfills - polyfills 7.2- (v1.19)"
173182
if: ${{ matrix.php == '5.4' }}
174183
run: |
175184
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php72/ --standard=PHPCompatibilitySymfonyPolyfillPHP72 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 5.3-
176185
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php73/ --standard=PHPCompatibilitySymfonyPolyfillPHP73 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 5.3-
177186
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php74/ --standard=PHPCompatibilitySymfonyPolyfillPHP74 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 5.3-
178187
179-
# The polyfills for PHP 7.2 and higher are compatible with PHP 7.1+ at version 1.30.
188+
# The polyfills for PHP 7.2-8.4 are compatible with PHP 7.1+ at version 1.30.
180189
- name: "Test running against the polyfills - polyfills 7.2- (v1.30)"
181190
if: ${{ matrix.php == '7.1' }}
182191
run: |
@@ -201,3 +210,4 @@ jobs:
201210
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php82/ --standard=PHPCompatibilitySymfonyPolyfillPHP82 --runtime-set testVersion 7.2-
202211
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php83/ --standard=PHPCompatibilitySymfonyPolyfillPHP83 --runtime-set testVersion 7.2-
203212
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php84/ --standard=PHPCompatibilitySymfonyPolyfillPHP84 --runtime-set testVersion 7.2-
213+
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php85/ --standard=PHPCompatibilitySymfonyPolyfillPHP85 --runtime-set testVersion 7.2-
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHPCompatibilitySymfonyPolyfillPHP85" 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.5 library.</description>
5+
6+
<rule ref="PHPCompatibility">
7+
<!-- https://github.com/symfony/polyfill-php85/blob/1.x/bootstrap.php -->
8+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.get_error_handlerFound"/>
9+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.get_exception_handlerFound"/>
10+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.array_firstFound"/>
11+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.array_lastFound"/>
12+
13+
<!-- https://github.com/symfony/polyfill-php85/tree/1.x/Resources/stubs -->
14+
<!--
15+
Detection for the DelayedTargetValidation and NoDiscard attributes is incomplete in PHPCompatibility 10.0.0-alpha1.
16+
This section should be filled out once the detection implementation is known.
17+
The following exclude is a temporary placeholder, which should be removed as soon as
18+
possible as it will ignore too much.
19+
-->
20+
<exclude name="PHPCompatibility.Attributes.NewAttributes.Found"/>
21+
</rule>
22+
23+
<!-- Prevent false positives being thrown when run over the code of polyfill-php84 itself. -->
24+
<rule ref="PHPCompatibility.Attributes.NewAttributes.PHPNativeAttributeFound">
25+
<exclude-pattern>/polyfill-php85/Resources/stubs/DelayedTargetValidation\.php$</exclude-pattern>
26+
<exclude-pattern>/polyfill-php85/Resources/stubs/NoDiscard\.php$</exclude-pattern>
27+
</rule>
28+
<rule ref="PHPCompatibility.Classes.NewClasses.attributeFound">
29+
<exclude-pattern>/polyfill-php85/Resources/stubs/DelayedTargetValidation\.php$</exclude-pattern>
30+
<exclude-pattern>/polyfill-php85/Resources/stubs/NoDiscard\.php$</exclude-pattern>
31+
</rule>
32+
33+
<!-- This is fine as the autoloading for this file should only ever be triggered when on PHP 8.0 or higher. -->
34+
<rule ref="PHPCompatibility.Classes.NewTypedProperties.Found">
35+
<exclude-pattern>/polyfill-php85/Resources/stubs/NoDiscard\.php$</exclude-pattern>
36+
</rule>
37+
38+
</ruleset>

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ These rulesets prevent false positives from the [PHPCompatibility standard][PHPC
2929
| [`polyfill-php82`] | `PHPCompatibilitySymfonyPolyfillPHP82` | |
3030
| [`polyfill-php83`] | `PHPCompatibilitySymfonyPolyfillPHP83` | |
3131
| [`polyfill-php84`] | `PHPCompatibilitySymfonyPolyfillPHP84` | |
32+
| [`polyfill-php85`] | `PHPCompatibilitySymfonyPolyfillPHP85` | |
3233

3334
> [!NOTE]
3435
> About "Includes":
@@ -105,6 +106,7 @@ vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP81
105106
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP82
106107
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP83
107108
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP84
109+
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP85
108110

109111
# You can also combine the standards if your project uses several:
110112
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP55,PHPCompatibilitySymfonyPolyfillPHP70,PHPCompatibilitySymfonyPolyfillPHP73
@@ -162,3 +164,4 @@ All code within the PHPCompatibility organisation is released under the GNU Less
162164
[`polyfill-php82`]: https://github.com/symfony/polyfill-php82
163165
[`polyfill-php83`]: https://github.com/symfony/polyfill-php83
164166
[`polyfill-php84`]: https://github.com/symfony/polyfill-php84
167+
[`polyfill-php85`]: https://github.com/symfony/polyfill-php85

Test/SymfonyPolyfillPHP85Test.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
/*
3+
* Test file to run PHP_CodeSniffer against to make sure the polyfills are correctly excluded.
4+
*/
5+
6+
echo get_error_handler();
7+
echo get_exception_handler();
8+
array_first($array);
9+
array_last($array);
10+
11+
#[DelayedTargetValidation]
12+
#[NoDiscard]
13+
function dummy() {}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"symfony/polyfill-php81": "1.x-dev",
4343
"symfony/polyfill-php82": "1.x-dev",
4444
"symfony/polyfill-php83": "1.x-dev",
45-
"symfony/polyfill-php84": "1.x-dev"
45+
"symfony/polyfill-php84": "1.x-dev",
46+
"symfony/polyfill-php85": "1.x-dev"
4647
},
4748
"prefer-stable" : true
4849
}

0 commit comments

Comments
 (0)