Skip to content

Commit 3c539b7

Browse files
authored
Merge pull request #68 from PHPCompatibility/feature/new-php82-polyfill-ruleset
Add `PHPCompatibilitySymfonyPolyfillPHP82` ruleset
2 parents f7a0b27 + 7089f22 commit 3c539b7

File tree

5 files changed

+90
-3
lines changed

5 files changed

+90
-3
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ jobs:
6161
diff -B ./PHPCompatibilitySymfonyPolyfillPHP74/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP74/ruleset.xml")
6262
diff -B ./PHPCompatibilitySymfonyPolyfillPHP80/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP80/ruleset.xml")
6363
diff -B ./PHPCompatibilitySymfonyPolyfillPHP81/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP81/ruleset.xml")
64+
diff -B ./PHPCompatibilitySymfonyPolyfillPHP82/ruleset.xml <(xmllint --format "./PHPCompatibilitySymfonyPolyfillPHP82/ruleset.xml")
6465
6566
test:
6667
# Don't run the cron job on forks.
@@ -109,13 +110,13 @@ jobs:
109110
# Remove the PHP 8.x polyfills on PHP < 7 as the minimum requirement is PHP 7.1 and the autoloading
110111
# of the polyfill bootstrap file via Composer would generate a parse error, blocking the DealerDirect plugin
111112
# from setting the installed_paths for PHPCS.
112-
composer remove --dev symfony/polyfill-php80 symfony/polyfill-php81 --no-update --no-scripts --no-interaction
113+
composer remove --dev symfony/polyfill-php80 symfony/polyfill-php81 symfony/polyfill-php82 --no-update --no-scripts --no-interaction
113114
composer require --no-update symfony/polyfill-php72:"1.19" symfony/polyfill-php73:"1.19" symfony/polyfill-php74:"1.19" --no-interaction
114115
115116
- name: "Conditionally require specific versions of the polyfills (PHP 7.1)"
116117
if: ${{ matrix.php == '7.1' }}
117118
run: |
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
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
119120
120121
- name: Conditionally update PHPCompatibility to develop version
121122
if: ${{ matrix.phpcompat != 'stable' }}
@@ -149,6 +150,7 @@ jobs:
149150
run: |
150151
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP80Test.php --standard=PHPCompatibilitySymfonyPolyfillPHP80 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
151152
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP81Test.php --standard=PHPCompatibilitySymfonyPolyfillPHP81 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
153+
vendor/bin/phpcs -ps ./Test/SymfonyPolyfillPHP82Test.php --standard=PHPCompatibilitySymfonyPolyfillPHP82 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
152154
153155
# Check that the rulesets don't throw unnecessary errors for the compat libraries themselves.
154156
# Note: the polyfills for PHP 5.4 - 7.1 have been decoupled from the monorepo at version 1.19.
@@ -179,6 +181,7 @@ jobs:
179181
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php74/ --standard=PHPCompatibilitySymfonyPolyfillPHP74 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
180182
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php80/ --standard=PHPCompatibilitySymfonyPolyfillPHP80 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
181183
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php81/ --standard=PHPCompatibilitySymfonyPolyfillPHP81 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
184+
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php82/ --standard=PHPCompatibilitySymfonyPolyfillPHP82 --exclude=PHPCompatibility.Upgrade.LowPHP --runtime-set testVersion 7.1-
182185
183186
# The polyfills for PHP 7.3 and higher are compatible with PHP 7.2+ at the current version.
184187
- name: "Test running against the polyfills - polyfills 7.3- (current)"
@@ -188,3 +191,4 @@ jobs:
188191
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php74/ --standard=PHPCompatibilitySymfonyPolyfillPHP74 --runtime-set testVersion 7.2-
189192
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php80/ --standard=PHPCompatibilitySymfonyPolyfillPHP80 --runtime-set testVersion 7.2-
190193
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php81/ --standard=PHPCompatibilitySymfonyPolyfillPHP81 --runtime-set testVersion 7.2-
194+
vendor/bin/phpcs -ps ./vendor/symfony/polyfill-php82/ --standard=PHPCompatibilitySymfonyPolyfillPHP82 --runtime-set testVersion 7.2-
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHPCompatibilitySymfonyPolyfillPHP82" 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.2 library.</description>
5+
6+
<rule ref="PHPCompatibility">
7+
<!-- https://github.com/symfony/polyfill-php82/blob/master/bootstrap.php -->
8+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.odbc_connection_string_is_quotedFound"/>
9+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.odbc_connection_string_should_quoteFound"/>
10+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.odbc_connection_string_quoteFound"/>
11+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.ini_parse_quantityFound"/>
12+
13+
<!-- https://github.com/symfony/polyfill-php82/tree/main/Resources/stubs -->
14+
<!--
15+
Detection for the AllowDynamicProperties and SensitiveParameter attributes is incomplete in PHPCompatibility 10.0.0-alpha1.
16+
This section should be filled out once the detection implementation is known.
17+
-->
18+
19+
<!-- https://github.com/symfony/polyfill-php82/tree/main/Resources/stubs/Random -->
20+
<exclude name="PHPCompatibility.Classes.NewClasses.random_brokenrandomengineerrorFound"/>
21+
<exclude name="PHPCompatibility.Classes.NewClasses.random_randomerrorFound"/>
22+
<exclude name="PHPCompatibility.Classes.NewClasses.random_randomexceptionFound"/>
23+
<exclude name="PHPCompatibility.Classes.NewClasses.random_engine_secureFound"/>
24+
<exclude name="PHPCompatibility.Interfaces.NewInterfaces.random_cryptosafeengineFound"/>
25+
<exclude name="PHPCompatibility.Interfaces.NewInterfaces.random_engineFound"/>
26+
</rule>
27+
28+
<!-- Prevent false positives being thrown when run over the code of polyfill-php82 itself. -->
29+
<rule ref="PHPCompatibility.Attributes.NewAttributes.PHPNativeAttributeFound">
30+
<exclude-pattern>/polyfill-php82/Resources/stubs/AllowDynamicProperties\.php$</exclude-pattern>
31+
<exclude-pattern>/polyfill-php82/Resources/stubs/SensitiveParameter\.php$</exclude-pattern>
32+
</rule>
33+
<rule ref="PHPCompatibility.Classes.NewClasses.attributeFound">
34+
<exclude-pattern>/polyfill-php82/Resources/stubs/AllowDynamicProperties\.php$</exclude-pattern>
35+
<exclude-pattern>/polyfill-php82/Resources/stubs/SensitiveParameter\.php$</exclude-pattern>
36+
</rule>
37+
<rule ref="PHPCompatibility.Namespaces.ReservedNames.randomFound">
38+
<exclude-pattern>/polyfill-php82/Resources/stubs/Random/*\.php$</exclude-pattern>
39+
</rule>
40+
41+
</ruleset>

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ These rulesets prevent false positives from the [PHPCompatibility standard][PHPC
2626
| [`polyfill-php74`] | `PHPCompatibilitySymfonyPolyfillPHP74` | |
2727
| [`polyfill-php80`] | `PHPCompatibilitySymfonyPolyfillPHP80` | |
2828
| [`polyfill-php81`] | `PHPCompatibilitySymfonyPolyfillPHP81` | |
29+
| [`polyfill-php82`] | `PHPCompatibilitySymfonyPolyfillPHP82` | |
2930

3031
> [!NOTE]
3132
> About "Includes":
@@ -99,6 +100,7 @@ vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP73
99100
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP74
100101
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP80
101102
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP81
103+
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP82
102104

103105
# You can also combine the standards if your project uses several:
104106
vendor/bin/phpcs -p . --standard=PHPCompatibilitySymfonyPolyfillPHP55,PHPCompatibilitySymfonyPolyfillPHP70,PHPCompatibilitySymfonyPolyfillPHP73
@@ -153,3 +155,4 @@ All code within the PHPCompatibility organisation is released under the GNU Less
153155
[`polyfill-php74`]: https://github.com/symfony/polyfill-php74
154156
[`polyfill-php80`]: https://github.com/symfony/polyfill-php80
155157
[`polyfill-php81`]: https://github.com/symfony/polyfill-php81
158+
[`polyfill-php82`]: https://github.com/symfony/polyfill-php82

Test/SymfonyPolyfillPHP82Test.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/*
3+
* Test file to run PHP_CodeSniffer against to make sure the polyfills are correctly excluded.
4+
*/
5+
6+
odbc_connection_string_is_quoted($str);
7+
odbc_connection_string_should_quote($str);
8+
odbc_connection_string_quote($str);
9+
echo ini_parse_quantity($shorthand);
10+
11+
class MyEngine implements Random\Engine {}
12+
$cl = function (
13+
Random\CryptoSafeEngine $param
14+
): Random\Engine\Secure {
15+
// Do something.
16+
};
17+
18+
try {
19+
} catch (Random\BrokenRandomEngineError $e) {
20+
} catch (Random\RandomException $e) {
21+
} catch (Random\RandomError $e) {
22+
}
23+
24+
echo AllowDynamicProperties::class;
25+
26+
#[AllowDynamicProperties]
27+
class HasDynamicProperties {}
28+
29+
if (is_a($token, SensitiveParameterValue::class)) {}
30+
31+
/*
32+
// This test will not help at this time as we can't just ignore the use of the SensitiveParameter attribute
33+
// with the current attribute handling in PHPCompatibility 10.0.
34+
function hasSensitiveData(
35+
#[SensitiveParameter]
36+
string $password
37+
) {}
38+
*/

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"symfony/polyfill-php73": "1.x-dev",
4040
"symfony/polyfill-php74": "1.x-dev",
4141
"symfony/polyfill-php80": "1.x-dev",
42-
"symfony/polyfill-php81": "1.x-dev"
42+
"symfony/polyfill-php81": "1.x-dev",
43+
"symfony/polyfill-php82": "1.x-dev"
4344
},
4445
"prefer-stable" : true
4546
}

0 commit comments

Comments
 (0)