Skip to content

Commit

Permalink
Merge pull request #54 from PHPCSStandards/feature/3386-psr1-sideffec…
Browse files Browse the repository at this point in the history
…ts-allow-for-ignore-with-errorcode

PSR1/SideEffects: improve recognition of disable/enable annotations
  • Loading branch information
jrfnl authored Dec 4, 2023
2 parents 334a64f + 5df13b3 commit 16db52c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ The file documents changes to the PHP_CodeSniffer project.
- Use composer or the phar files

### Fixed
- Fixed bug #3386 : PSR1/SideEffects : improved recognition of disable/enable annotations
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Fixed bug #3557 : Squiz.Arrays.ArrayDeclaration will now ignore PHP 7.4 array unpacking when determining whether an array is associative
- Thanks to Volker Dusch (@edorian) for the patch
- Fixed bug #3717 : Squiz.Commenting.FunctionComment: fixed false positive for InvalidNoReturn when type is never
Expand Down
6 changes: 4 additions & 2 deletions src/Standards/PSR1/Sniffs/Files/SideEffectsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,17 @@ private function searchForConflict($phpcsFile, $start, $end, $tokens)
&& (empty($tokens[$i]['sniffCodes']) === true
|| isset($tokens[$i]['sniffCodes']['PSR1']) === true
|| isset($tokens[$i]['sniffCodes']['PSR1.Files']) === true
|| isset($tokens[$i]['sniffCodes']['PSR1.Files.SideEffects']) === true)
|| isset($tokens[$i]['sniffCodes']['PSR1.Files.SideEffects']) === true
|| isset($tokens[$i]['sniffCodes']['PSR1.Files.SideEffects.FoundWithSymbols']) === true)
) {
do {
$i = $phpcsFile->findNext(T_PHPCS_ENABLE, ($i + 1));
} while ($i !== false
&& empty($tokens[$i]['sniffCodes']) === false
&& isset($tokens[$i]['sniffCodes']['PSR1']) === false
&& isset($tokens[$i]['sniffCodes']['PSR1.Files']) === false
&& isset($tokens[$i]['sniffCodes']['PSR1.Files.SideEffects']) === false);
&& isset($tokens[$i]['sniffCodes']['PSR1.Files.SideEffects']) === false
&& isset($tokens[$i]['sniffCodes']['PSR1.Files.SideEffects.FoundWithSymbols']) === false);

if ($i === false) {
// The entire rest of the file is disabled,
Expand Down
8 changes: 8 additions & 0 deletions src/Standards/PSR1/Tests/Files/SideEffectsUnitTest.17.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
define("MAXSIZE", 100);
// phpcs:enable
$defined = true;
if (defined('MINSIZE') === false) {
$defined = false;
}

0 comments on commit 16db52c

Please sign in to comment.