Last active
December 31, 2015 15:19
-
-
Save edorian/8005781 to your computer and use it in GitHub Desktop.
Disallow certain annotations in doc blocks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class RgStandard_Sniffs_Rg_DisallowAnnotationSniff implements PHP_CodeSniffer_Sniff { | |
private $disallowedAnnotations = [ | |
'@abstract' => 'Please use the language construct instead.' | |
]; | |
public function register() { | |
return [T_DOC_COMMENT]; | |
} | |
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPointer) { | |
$tokens = $phpcsFile->getTokens(); | |
$content = $tokens[$stackPointer]['content']; | |
foreach ($this->disallowedAnnotations as $annotation => $alternative) { | |
if (strpos($content, $annotation) !== false) { | |
$phpcsFile->addError('The annotation "' . $annotation . '" is not allowed. ' . $alternative, $stackPointer); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment