Skip to content

Commit

Permalink
PSR1.Files.SideEffects now respects the new phpcs:disable comment syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Oct 30, 2017
1 parent 389e52f commit 5524f2d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- If they are at the end of an existing line, they will only ignore the line they are on
-- Stops some lines from accidently being ignored
-- Same rule applies for the new phpcs:ignore comment syntax
- PSR1.Files.SideEffects now respects the new phpcs:disable comment syntax
-- The sniff will no longer check any code that is between phpcs:disable and phpcs:enable comments
-- The sniff does not support the phpcs:ignore; you must wrap code structures with disable/enable comments
-- Previously, there was no way to have this sniff ignore parts of a file
- Array properties specified in ruleset files now have their keys and values trimmed
-- This saves having to do this in individual sniffs, and stops errors introduced by whitespace in rulesets
-- Thanks to Juliette Reinders Folmer for the patch
Expand Down
12 changes: 12 additions & 0 deletions src/Standards/PSR1/Sniffs/Files/SideEffectsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ private function searchForConflict($phpcsFile, $start, $end, $tokens)
$firstSymbol = null;
$firstEffect = null;
for ($i = $start; $i <= $end; $i++) {
// Respect phpcs:disable comments.
if ($tokens[$i]['code'] === T_PHPCS_DISABLE) {
$i = $phpcsFile->findNext(T_PHPCS_ENABLE, $i);
if ($i === false) {
// The entire rest of the file is disabled,
// so return what we have so far.
break;
}

continue;
}

// Ignore whitespace and comments.
if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === true) {
continue;
Expand Down

0 comments on commit 5524f2d

Please sign in to comment.