Skip to content

Commit 78701de

Browse files
authored
Merge pull request #69 from PHPCompatibility/feature/new-php83-polyfill-ruleset
Add `PHPCompatibilitySymfonyPolyfillPHP83` ruleset
2 parents 3c539b7 + 47a180a commit 78701de

File tree

5 files changed

+136
-3
lines changed

5 files changed

+136
-3
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ jobs:
6262
diff -B ./PHPCompatibilitySymfonyPolyfillPHP80/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP80/ruleset.xml")
6363
diff -B ./PHPCompatibilitySymfonyPolyfillPHP81/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP81/ruleset.xml")
6464
diff -B ./PHPCompatibilitySymfonyPolyfillPHP82/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP82/ruleset.xml")
65+
diff -B ./PHPCompatibilitySymfonyPolyfillPHP83/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP83/ruleset.xml")
6566
6667
test:
6768
# Don't run the cron job on forks.
@@ -110,13 +111,13 @@ jobs:
110111
# Remove the PHP 8.x polyfills on PHP < 7 as the minimum requirement is PHP 7.1 and the autoloading
111112
# of the polyfill bootstrap file via Composer would generate a parse error, blocking the DealerDirect plugin
112113
# from setting the installed_paths for PHPCS.
113-
composer remove --dev symfony/polyfill-php80 symfony/polyfill-php81 symfony/polyfill-php82 --no-update --no-scripts --no-interaction
114+
composer remove --dev symfony/polyfill-php80 symfony/polyfill-php81 symfony/polyfill-php82 symfony/polyfill-php83 --no-update --no-scripts --no-interaction
114115
composer require --no-update symfony/polyfill-php72:"1.19" symfony/polyfill-php73:"1.19" symfony/polyfill-php74:"1.19" --no-interaction
115116
116117
- name: "Conditionally require specific versions of the polyfills (PHP 7.1)"
117118
if: ${{ matrix.php == '7.1' }}
118119
run: |
119-
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" --no-interaction
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
120121
121122
- name: Conditionally update PHPCompatibility to develop version
122123
if: ${{ matrix.phpcompat != 'stable' }}
@@ -151,6 +152,7 @@ jobs:
151152
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP80Test.php --standard=PHPCompatibilitySymfonyPolyfillPHP80 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
152153
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP81Test.php --standard=PHPCompatibilitySymfonyPolyfillPHP81 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
153154
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP82Test.php --standard=PHPCompatibilitySymfonyPolyfillPHP82 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
155+
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP83Test.php --standard=PHPCompatibilitySymfonyPolyfillPHP83 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
154156
155157
# Check that the rulesets don't throw unnecessary errors for the compat libraries themselves.
156158
# Note: the polyfills for PHP 5.4 - 7.1 have been decoupled from the monorepo at version 1.19.
@@ -182,6 +184,8 @@ jobs:
182184
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php80/ --standard=PHPCompatibilitySymfonyPolyfillPHP80 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
183185
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php81/ --standard=PHPCompatibilitySymfonyPolyfillPHP81 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
184186
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php82/ --standard=PHPCompatibilitySymfonyPolyfillPHP82 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
187+
# The PHP 8.3 polyfills at version 1.30 are not tested against PHP 7.1 as they are not in actual fact
188+
# compatible with PHP 7.1. This was correctly detected by PHPCompatibility and would cause this test to fail.
185189
186190
# The polyfills for PHP 7.3 and higher are compatible with PHP 7.2+ at the current version.
187191
- name: "Test running against the polyfills - polyfills 7.3- (current)"
@@ -192,3 +196,4 @@ jobs:
192196
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php80/ --standard=PHPCompatibilitySymfonyPolyfillPHP80 --runtime-set testVersion 7.2-
193197
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php81/ --standard=PHPCompatibilitySymfonyPolyfillPHP81 --runtime-set testVersion 7.2-
194198
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php82/ --standard=PHPCompatibilitySymfonyPolyfillPHP82 --runtime-set testVersion 7.2-
199+
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php83/ --standard=PHPCompatibilitySymfonyPolyfillPHP83 --runtime-set testVersion 7.2-
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHPCompatibilitySymfonyPolyfillPHP83" 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.3 library.</description>
5+
6+
<rule ref="PHPCompatibility">
7+
<!-- https://github.com/symfony/polyfill-php83/blob/master/bootstrap.php -->
8+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.json_validateFound"/>
9+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.mb_str_padFound"/>
10+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.stream_context_set_optionsFound"/>
11+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.str_incrementFound"/>
12+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.str_decrementFound"/>
13+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.ldap_exop_syncFound"/>
14+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.ldap_connect_walletFound"/>
15+
16+
<!-- https://github.com/symfony/polyfill-php83/tree/main/Resources/stubs -->
17+
<!--
18+
Detection for the Override attributes is incomplete in PHPCompatibility 10.0.0-alpha1.
19+
Handling for this should be added once the detection implementation is known.
20+
-->
21+
<exclude name="PHPCompatibility.Classes.NewClasses.dateerrorFound"/>
22+
<exclude name="PHPCompatibility.Classes.NewClasses.dateexceptionFound"/>
23+
<exclude name="PHPCompatibility.Classes.NewClasses.dateinvalidoperationexceptionFound"/>
24+
<exclude name="PHPCompatibility.Classes.NewClasses.dateinvalidtimezoneexceptionFound"/>
25+
<exclude name="PHPCompatibility.Classes.NewClasses.datemalformedintervalstringexceptionFound"/>
26+
<exclude name="PHPCompatibility.Classes.NewClasses.datemalformedperiodstringexceptionFound"/>
27+
<exclude name="PHPCompatibility.Classes.NewClasses.datemalformedstringexceptionFound"/>
28+
<exclude name="PHPCompatibility.Classes.NewClasses.dateobjecterrorFound"/>
29+
<exclude name="PHPCompatibility.Classes.NewClasses.daterangeerrorFound"/>
30+
<exclude name="PHPCompatibility.Classes.NewClasses.sqlite3exceptionFound"/>
31+
</rule>
32+
33+
<!-- Prevent false positives being thrown when run over the code of polyfill-php83 itself. -->
34+
<rule ref="PHPCompatibility.Attributes.NewAttributes.PHPNativeAttributeFound">
35+
<exclude-pattern>/polyfill-php83/Resources/stubs/Override\.php$</exclude-pattern>
36+
</rule>
37+
<rule ref="PHPCompatibility.Classes.NewClasses.attributeFound">
38+
<exclude-pattern>/polyfill-php83/Resources/stubs/Override\.php$</exclude-pattern>
39+
</rule>
40+
41+
<rule ref="PHPCompatibility.FunctionUse.OptionalToRequiredFunctionParameters.stream_context_set_option_option_nameSoftRequired">
42+
<exclude-pattern>/polyfill-php83/bootstrap\.php$</exclude-pattern>
43+
</rule>
44+
<rule ref="PHPCompatibility.FunctionUse.OptionalToRequiredFunctionParameters.stream_context_set_option_valueSoftRequired">
45+
<exclude-pattern>/polyfill-php83/bootstrap\.php$</exclude-pattern>
46+
</rule>
47+
<rule ref="PHPCompatibility.FunctionUse.RemovedFunctionParameters.ldap_exop_response_dataDeprecated">
48+
<exclude-pattern>/polyfill-php83/bootstrap\.php$</exclude-pattern>
49+
<exclude-pattern>/polyfill-php83/bootstrap81\.php$</exclude-pattern>
50+
</rule>
51+
<rule ref="PHPCompatibility.FunctionUse.RemovedFunctionParameters.ldap_exop_response_oidDeprecated">
52+
<exclude-pattern>/polyfill-php83/bootstrap\.php$</exclude-pattern>
53+
<exclude-pattern>/polyfill-php83/bootstrap81\.php$</exclude-pattern>
54+
</rule>
55+
<rule ref="PHPCompatibility.ParameterValues.RemovedLdapConnectSignatures.DeprecatedThreePlusParamSignature">
56+
<exclude-pattern>/polyfill-php83/bootstrap\.php$</exclude-pattern>
57+
<exclude-pattern>/polyfill-php83/bootstrap81\.php$</exclude-pattern>
58+
</rule>
59+
60+
<!-- These are fine as this file will only be used for PHP 8.1 and 8.2. -->
61+
<rule ref="PHPCompatibility.Classes.NewClasses.ldap_connectionFound">
62+
<exclude-pattern>/polyfill-php83/bootstrap81\.php$</exclude-pattern>
63+
</rule>
64+
<rule ref="PHPCompatibility.FunctionUse.NewFunctionParameters.ldap_exop_controlsFound">
65+
<exclude-pattern>/polyfill-php83/bootstrap81\.php$</exclude-pattern>
66+
</rule>
67+
<rule ref="PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.UnionTypeFound">
68+
<exclude-pattern>/polyfill-php83/bootstrap81\.php$</exclude-pattern>
69+
</rule>
70+
<rule ref="PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.falseFound">
71+
<exclude-pattern>/polyfill-php83/bootstrap81\.php$</exclude-pattern>
72+
</rule>
73+
<rule ref="PHPCompatibility.Attributes.NewAttributes.PHPNativeAttributeFound">
74+
<exclude-pattern>/polyfill-php83/bootstrap81\.php$</exclude-pattern>
75+
</rule>
76+
<rule ref="PHPCompatibility.Attributes.NewAttributes.FoundInline">
77+
<exclude-pattern>/polyfill-php83/bootstrap81\.php$</exclude-pattern>
78+
</rule>
79+
80+
<!--
81+
Not a false positive, but a bug in the Symfony PHP 8.3 polyfill package.
82+
Bug has been reported: https://github.com/symfony/polyfill/issues/499#issuecomment-3430297592
83+
Temporarily silencing the error as this needs to be solved upstream.
84+
-->
85+
<rule ref="PHPCompatibility.Classes.NewClasses.valueerrorFound">
86+
<exclude-pattern>/polyfill-php83/Php83\.php$</exclude-pattern>
87+
</rule>
88+
89+
<!--
90+
Not a false positive, but a bug in the Symfony PHP 8.3 polyfill package.
91+
Bug has been reported: https://github.com/symfony/polyfill/issues/550
92+
Temporarily silencing the error as this needs to be solved upstream.
93+
-->
94+
<rule ref="PHPCompatibility.FunctionUse.NewFunctionParameters.ldap_exop_controlsFound">
95+
<exclude-pattern>/polyfill-php83/bootstrap\.php$</exclude-pattern>
96+
</rule>
97+
98+
</ruleset>

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ These rulesets prevent false positives from the [PHPCompatibility standard][PHPC
2727
| [`polyfill-php80`] | `PHPCompatibilitySymfonyPolyfillPHP80` | |
2828
| [`polyfill-php81`] | `PHPCompatibilitySymfonyPolyfillPHP81` | |
2929
| [`polyfill-php82`] | `PHPCompatibilitySymfonyPolyfillPHP82` | |
30+
| [`polyfill-php83`] | `PHPCompatibilitySymfonyPolyfillPHP83` | |
3031

3132
> [!NOTE]
3233
> About "Includes":
@@ -101,6 +102,7 @@ vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP74
101102
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP80
102103
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP81
103104
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP82
105+
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP83
104106

105107
# You can also combine the standards if your project uses several:
106108
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP55,PHPCompatibilitySymfonyPolyfillPHP70,PHPCompatibilitySymfonyPolyfillPHP73
@@ -156,3 +158,4 @@ All code within the PHPCompatibility organisation is released under the GNU Less
156158
[`polyfill-php80`]: https://github.com/symfony/polyfill-php80
157159
[`polyfill-php81`]: https://github.com/symfony/polyfill-php81
158160
[`polyfill-php82`]: https://github.com/symfony/polyfill-php82
161+
[`polyfill-php83`]: https://github.com/symfony/polyfill-php83

Test/SymfonyPolyfillPHP83Test.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/*
3+
* Test file to run PHP_CodeSniffer against to make sure the polyfills are correctly excluded.
4+
*/
5+
6+
json_validate($json, $depth);
7+
mb_str_pad($string, $length);
8+
str_increment($string);
9+
str_decrement($string);
10+
11+
stream_context_set_options($context, $options);
12+
ldap_exop_sync($ldap, $request_oid);
13+
ldap_connect_wallet($uri, $wallet, $password);
14+
15+
echo Override::class;
16+
17+
class Foo extends DateError {}
18+
19+
if (is_a($token, DateException::class)) {}
20+
21+
try {
22+
} catch (DateInvalidOperationException | DateInvalidTimeZoneException $e) {
23+
} catch (DateMalformedIntervalStringException | DateMalformedPeriodStringException | DateMalformedStringException $e) {
24+
} catch (DateObjectError | DateRangeError $e) {
25+
} catch (SQLite3Exception $e) {
26+
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
"symfony/polyfill-php74": "1.x-dev",
4141
"symfony/polyfill-php80": "1.x-dev",
4242
"symfony/polyfill-php81": "1.x-dev",
43-
"symfony/polyfill-php82": "1.x-dev"
43+
"symfony/polyfill-php82": "1.x-dev",
44+
"symfony/polyfill-php83": "1.x-dev"
4445
},
4546
"prefer-stable" : true
4647
}

0 commit comments

Comments
 (0)