Skip to content

Commit

Permalink
Add fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
Boegie committed Jan 29, 2024
1 parent f525910 commit 3d992e0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ public function processFunctionCall(

if ($tokens[($stackPtr - 1)]['type'] !== 'T_ASPERAND') {
$error = 'All trigger_error calls used for deprecation must be prefixed by an "@"';
$phpcsFile->addError($error, $stackPtr, 'UnsilencedDeprecation');
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'UnsilencedDeprecation');
if ($fix === true) {
$phpcsFile->fixer->addContentBefore($stackPtr, '@');
}
}

}//end processFunctionCall()
Expand Down
2 changes: 1 addition & 1 deletion tests/Drupal/Semantics/UnsilencedDeprecationUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ trigger_error('CommentTestBase is deprecated in drupal 8.4.0', E_USER_SOMETHING_

// E_USER_DEPRECATED, so silenced is fine...
@trigger_error('CommentTestBase is deprecated in drupal 8.4.0', E_USER_DEPRECATED);
//... but unsilenced fails.
// ... but unsilenced fails.
trigger_error('CommentTestBase is deprecated in drupal 8.4.0', E_USER_DEPRECATED);
19 changes: 19 additions & 0 deletions tests/Drupal/Semantics/UnsilencedDeprecationUnitTest.inc.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/**
* @file
* Test data for the relaxed version of FunctionUnsilencedDeprecationSniff coding standard.
*/

// No second parameter, so cannot fail it, both silenced and unsilenced.
@trigger_error('CommentTestBase is deprecated in drupal 8.4.0');
trigger_error('CommentTestBase is deprecated in drupal 8.4.0');

// Not E_USER_DEPRECATED, so cannot fail it, both silenced and unsilenced.
@trigger_error('CommentTestBase is deprecated in drupal 8.4.0', E_USER_SOMETHING_ELSE);
trigger_error('CommentTestBase is deprecated in drupal 8.4.0', E_USER_SOMETHING_ELSE);

// E_USER_DEPRECATED, so silenced is fine...
@trigger_error('CommentTestBase is deprecated in drupal 8.4.0', E_USER_DEPRECATED);
// ... but unsilenced fails.
@trigger_error('CommentTestBase is deprecated in drupal 8.4.0', E_USER_DEPRECATED);

0 comments on commit 3d992e0

Please sign in to comment.