Skip to content

Commit 5ce9f2c

Browse files
committed
Ruleset: prevent false positives on polyfill code
When `PHPCompatibility(PasswordCompat)` is run over the code in the `password_compat` repo itself, it will detect some non-issues. ``` FILE: password_compat\lib\password.php ------------------------------------------------------------------------------------------ FOUND 3 ERRORS AFFECTING 1 LINE ------------------------------------------------------------------------------------------ 105 | ERROR | Extension 'mcrypt' is deprecated since PHP 7.1 and removed since PHP 7.2; | | Use openssl (preferred) or pecl/mcrypt once available instead | | (PHPCompatibility.Extensions.RemovedExtensions.mcryptDeprecatedRemoved) 105 | ERROR | Function mcrypt_create_iv() is deprecated since PHP 7.1 and removed since | | PHP 7.2; Use random_bytes() or OpenSSL instead | | (PHPCompatibility.FunctionUse.RemovedFunctions.mcrypt_create_ivDeprecatedRemoved) 105 | ERROR | The constant "MCRYPT_DEV_URANDOM" is deprecated since PHP 7.1 and removed | | since PHP 7.2 | | (PHPCompatibility.Constants.RemovedConstants.mcrypt_dev_urandomDeprecatedRemoved) ------------------------------------------------------------------------------------------ ``` The code in the `lib/password.php` file is all wrapped within `defined()` and/or `function_exists()` conditions and will never be executed on PHP 5.5+ as the functionality being polyfilled is by then provided natively by PHP. This simple change prevents these non-issues from being reported. This fix does rely on people having installed the code in a directory called `password_compat` or, for composer installs `password-compat`.
1 parent 35f63c1 commit 5ce9f2c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

PHPCompatibilityPasswordCompat/ruleset.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,15 @@
1313
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.password_verifyFound"/>
1414
</rule>
1515

16+
<!-- Prevent false positives being thrown when run over the code of password_compat itself. -->
17+
<rule ref="PHPCompatibility.Constants.RemovedConstants.mcrypt_dev_urandomDeprecatedRemoved">
18+
<exclude-pattern>/password[-_]compat/lib/password\.php$</exclude-pattern>
19+
</rule>
20+
<rule ref="PHPCompatibility.Extensions.RemovedExtensions.mcryptDeprecatedRemoved">
21+
<exclude-pattern>/password[-_]compat/lib/password\.php$</exclude-pattern>
22+
</rule>
23+
<rule ref="PHPCompatibility.FunctionUse.RemovedFunctions.mcrypt_create_ivDeprecatedRemoved">
24+
<exclude-pattern>/password[-_]compat/lib/password\.php$</exclude-pattern>
25+
</rule>
26+
1627
</ruleset>

0 commit comments

Comments
 (0)