Skip to content

Commit 49b99f7

Browse files
authored
Merge pull request #70 from PHPCompatibility/feature/new-php84-polyfill-ruleset
Add `PHPCompatibilitySymfonyPolyfillPHP84` ruleset
2 parents 78701de + 29067d3 commit 49b99f7

File tree

5 files changed

+119
-3
lines changed

5 files changed

+119
-3
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ jobs:
6363
diff -B ./PHPCompatibilitySymfonyPolyfillPHP81/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP81/ruleset.xml")
6464
diff -B ./PHPCompatibilitySymfonyPolyfillPHP82/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP82/ruleset.xml")
6565
diff -B ./PHPCompatibilitySymfonyPolyfillPHP83/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP83/ruleset.xml")
66+
diff -B ./PHPCompatibilitySymfonyPolyfillPHP84/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP84/ruleset.xml")
6667
6768
test:
6869
# Don't run the cron job on forks.
@@ -111,13 +112,13 @@ jobs:
111112
# Remove the PHP 8.x polyfills on PHP < 7 as the minimum requirement is PHP 7.1 and the autoloading
112113
# of the polyfill bootstrap file via Composer would generate a parse error, blocking the DealerDirect plugin
113114
# from setting the installed_paths for PHPCS.
114-
composer remove --dev symfony/polyfill-php80 symfony/polyfill-php81 symfony/polyfill-php82 symfony/polyfill-php83 --no-update --no-scripts --no-interaction
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
115116
composer require --no-update symfony/polyfill-php72:"1.19" symfony/polyfill-php73:"1.19" symfony/polyfill-php74:"1.19" --no-interaction
116117
117118
- name: "Conditionally require specific versions of the polyfills (PHP 7.1)"
118119
if: ${{ matrix.php == '7.1' }}
119120
run: |
120-
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" --no-interaction
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
121122
122123
- name: Conditionally update PHPCompatibility to develop version
123124
if: ${{ matrix.phpcompat != 'stable' }}
@@ -153,6 +154,7 @@ jobs:
153154
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP81Test.php --standard=PHPCompatibilitySymfonyPolyfillPHP81 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
154155
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP82Test.php --standard=PHPCompatibilitySymfonyPolyfillPHP82 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
155156
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP83Test.php --standard=PHPCompatibilitySymfonyPolyfillPHP83 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
157+
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP84Test.php --standard=PHPCompatibilitySymfonyPolyfillPHP84 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
156158
157159
# Check that the rulesets don't throw unnecessary errors for the compat libraries themselves.
158160
# Note: the polyfills for PHP 5.4 - 7.1 have been decoupled from the monorepo at version 1.19.
@@ -186,6 +188,7 @@ jobs:
186188
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php82/ --standard=PHPCompatibilitySymfonyPolyfillPHP82 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
187189
# The PHP 8.3 polyfills at version 1.30 are not tested against PHP 7.1 as they are not in actual fact
188190
# compatible with PHP 7.1. This was correctly detected by PHPCompatibility and would cause this test to fail.
191+
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php84/ --standard=PHPCompatibilitySymfonyPolyfillPHP84 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
189192
190193
# The polyfills for PHP 7.3 and higher are compatible with PHP 7.2+ at the current version.
191194
- name: "Test running against the polyfills - polyfills 7.3- (current)"
@@ -197,3 +200,4 @@ jobs:
197200
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php81/ --standard=PHPCompatibilitySymfonyPolyfillPHP81 --runtime-set testVersion 7.2-
198201
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php82/ --standard=PHPCompatibilitySymfonyPolyfillPHP82 --runtime-set testVersion 7.2-
199202
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php83/ --standard=PHPCompatibilitySymfonyPolyfillPHP83 --runtime-set testVersion 7.2-
203+
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php84/ --standard=PHPCompatibilitySymfonyPolyfillPHP84 --runtime-set testVersion 7.2-
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHPCompatibilitySymfonyPolyfillPHP84" 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.4 library.</description>
5+
6+
<rule ref="PHPCompatibility">
7+
<!-- https://github.com/symfony/polyfill-php84/blob/master/bootstrap.php -->
8+
<exclude name="PHPCompatibility.Constants.NewConstants.curl_http_version_3Found"/>
9+
<exclude name="PHPCompatibility.Constants.NewConstants.curl_http_version_3onlyFound"/>
10+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.array_findFound"/>
11+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.array_find_keyFound"/>
12+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.array_anyFound"/>
13+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.array_allFound"/>
14+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.fpowFound"/>
15+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.mb_ucfirstFound"/>
16+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.mb_lcfirstFound"/>
17+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.mb_trimFound"/>
18+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.mb_ltrimFound"/>
19+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.mb_rtrimFound"/>
20+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.bcdivmodFound"/>
21+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.grapheme_str_splitFound"/>
22+
23+
<!-- https://github.com/symfony/polyfill-php84/tree/main/Resources/stubs -->
24+
<!--
25+
Detection for the Deprecated attribute is incomplete in PHPCompatibility 10.0.0-alpha1.
26+
Handling for this should be added once the detection implementation is known.
27+
The following exclude is a temporary placeholder, which should be removed as soon as
28+
possible as it will ignore too much.
29+
-->
30+
<exclude name="PHPCompatibility.Attributes.NewAttributes.PHPStormAttributeFound"/>
31+
32+
<exclude name="PHPCompatibility.Classes.NewClasses.reflectionconstantFound"/>
33+
</rule>
34+
35+
<!-- Prevent false positives being thrown when run over the code of polyfill-php83 itself. -->
36+
<rule ref="PHPCompatibility.FunctionUse.RequiredToOptionalFunctionParameters.bcscale_scaleMissing">
37+
<exclude-pattern>/polyfill-php84/Php84\.php$</exclude-pattern>
38+
</rule>
39+
<rule ref="PHPCompatibility.Attributes.NewAttributes.PHPNativeAttributeFound">
40+
<exclude-pattern>/polyfill-php84/Resources/stubs/Deprecated\.php$</exclude-pattern>
41+
</rule>
42+
<rule ref="PHPCompatibility.Classes.NewClasses.attributeFound">
43+
<exclude-pattern>/polyfill-php84/Resources/stubs/Deprecated\.php$</exclude-pattern>
44+
</rule>
45+
<rule ref="PHPCompatibility.FunctionUse.NewFunctions.get_debug_typeFound">
46+
<exclude-pattern>/polyfill-php84/Resources/stubs/ReflectionConstant\.php$</exclude-pattern>
47+
</rule>
48+
49+
<!-- This is fine as the autoloading for this file should only ever be triggered when on PHP 8.0 or higher. -->
50+
<rule ref="PHPCompatibility.Classes.NewTypedProperties.Found">
51+
<exclude-pattern>/polyfill-php84/Resources/stubs/Deprecated\.php$</exclude-pattern>
52+
</rule>
53+
54+
<!-- These are fine as this file will only be used for PHP 8.2 and 8.3. -->
55+
<rule ref="PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.UnionTypeFound">
56+
<exclude-pattern>/polyfill-php84/bootstrap82\.php$</exclude-pattern>
57+
</rule>
58+
<rule ref="PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.falseFound">
59+
<exclude-pattern>/polyfill-php84/bootstrap82\.php$</exclude-pattern>
60+
</rule>
61+
62+
<!--
63+
Not a false positive, but a bug in the Symfony PHP 8.4 polyfill package.
64+
Bug has been reported: https://github.com/symfony/polyfill/issues/499#issuecomment-3430423298
65+
Temporarily silencing the error as this needs to be solved upstream.
66+
-->
67+
<rule ref="PHPCompatibility.Classes.NewClasses.valueerrorFound">
68+
<exclude-pattern>/polyfill-php84/Php84\.php$</exclude-pattern>
69+
</rule>
70+
71+
<!--
72+
Not a false positive, but a bug in the Symfony PHP 8.4 polyfill package.
73+
Bug has been reported: https://github.com/symfony/polyfill/issues/551
74+
Temporarily silencing the error as this needs to be solved upstream.
75+
-->
76+
<rule ref="PHPCompatibility.Classes.NewReadonlyProperties.Found">
77+
<exclude-pattern>/polyfill-php84/Resources/stubs/Deprecated\.php$</exclude-pattern>
78+
</rule>
79+
80+
</ruleset>

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ These rulesets prevent false positives from the [PHPCompatibility standard][PHPC
2828
| [`polyfill-php81`] | `PHPCompatibilitySymfonyPolyfillPHP81` | |
2929
| [`polyfill-php82`] | `PHPCompatibilitySymfonyPolyfillPHP82` | |
3030
| [`polyfill-php83`] | `PHPCompatibilitySymfonyPolyfillPHP83` | |
31+
| [`polyfill-php84`] | `PHPCompatibilitySymfonyPolyfillPHP84` | |
3132

3233
> [!NOTE]
3334
> About "Includes":
@@ -103,6 +104,7 @@ vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP80
103104
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP81
104105
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP82
105106
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP83
107+
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP84
106108

107109
# You can also combine the standards if your project uses several:
108110
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP55,PHPCompatibilitySymfonyPolyfillPHP70,PHPCompatibilitySymfonyPolyfillPHP73
@@ -159,3 +161,4 @@ All code within the PHPCompatibility organisation is released under the GNU Less
159161
[`polyfill-php81`]: https://github.com/symfony/polyfill-php81
160162
[`polyfill-php82`]: https://github.com/symfony/polyfill-php82
161163
[`polyfill-php83`]: https://github.com/symfony/polyfill-php83
164+
[`polyfill-php84`]: https://github.com/symfony/polyfill-php84

Test/SymfonyPolyfillPHP84Test.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/*
3+
* Test file to run PHP_CodeSniffer against to make sure the polyfills are correctly excluded.
4+
*/
5+
6+
echo CURL_HTTP_VERSION_3;
7+
echo CURL_HTTP_VERSION_3ONLY;
8+
9+
array_find($array, $callback);
10+
array_find_key($array, $callback);
11+
array_any($array, $callback);
12+
array_all($array, $callback);
13+
fpow($num, $exponent);
14+
15+
echo mb_ucfirst($string);
16+
echo mb_lcfirst($string);
17+
mb_trim($string);
18+
mb_ltrim($string);
19+
mb_rtrim($string);
20+
21+
bcdivmod($num1, $num2);
22+
23+
grapheme_str_split($string);
24+
25+
$r = new ReflectionConstant(ClassName::CONSTANT_NAME);
26+
27+
#[Deprecated]
28+
function foo() {}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
"symfony/polyfill-php80": "1.x-dev",
4242
"symfony/polyfill-php81": "1.x-dev",
4343
"symfony/polyfill-php82": "1.x-dev",
44-
"symfony/polyfill-php83": "1.x-dev"
44+
"symfony/polyfill-php83": "1.x-dev",
45+
"symfony/polyfill-php84": "1.x-dev"
4546
},
4647
"prefer-stable" : true
4748
}

0 commit comments

Comments
 (0)