Skip to content

Commit

Permalink
Handle backslash-prefixed trigger_error calls (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoll authored and djoos committed Nov 29, 2019
1 parent 2b418e3 commit 3ddef0c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
26 changes: 18 additions & 8 deletions Symfony/Sniffs/Errors/UserDeprecatedSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 73,28 @@ public function process(File $phpcsFile, $stackPtr)
break;
}

if ($tokens[$string]['content'] === 'E_USER_DEPRECATED'
&& '@' !== $tokens[$stackPtr -1]['content']
) {
$error = 'Calls to trigger_error with type E_USER_DEPRECATED ';
$error .= 'must be switched to opt-in via @ operator';
$opener = $string 1;

$phpcsFile->addError($error, $stackPtr, 'Invalid');
if ($tokens[$string]['content'] !== 'E_USER_DEPRECATED') {
continue;
}

break;
if ('@' === $tokens[$stackPtr -1]['content']) {
continue;
}

$opener = $string 1;
if ('@' === $tokens[$stackPtr - 2]['content']
&& 'T_NS_SEPARATOR' === $tokens[$stackPtr - 1]['type']
) {
continue;
}

$error = 'Calls to trigger_error with type E_USER_DEPRECATED ';
$error .= 'must be switched to opt-in via @ operator';

$phpcsFile->addError($error, $stackPtr, 'Invalid');

break;
} while ($opener < $closer);
}

Expand Down
8 changes: 8 additions & 0 deletions Symfony/Tests/Errors/UserDeprecatedUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 5,11 @@ trigger_error('deprecation', E_USER_DEPRECATED);
@trigger_error('deprecation', E_USER_DEPRECATED);

trigger_error('An error occurred.');

\trigger_error('deprecation', E_USER_DEPRECATED);

@\trigger_error('deprecation', E_USER_DEPRECATED);

\trigger_error('An error occurred.');

trigger_error('warning', E_WARNING);
1 change: 1 addition & 0 deletions Symfony/Tests/Errors/UserDeprecatedUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 44,7 @@ public function getErrorList()
{
return array(
3 => 1,
9 => 1,
);
}

Expand Down

0 comments on commit 3ddef0c

Please sign in to comment.