Skip to content

Instantly share code, notes, and snippets.

@edorian
Last active December 31, 2015 15:19
Show Gist options
  • Save edorian/8005781 to your computer and use it in GitHub Desktop.
Save edorian/8005781 to your computer and use it in GitHub Desktop.
Disallow certain annotations in doc blocks
<?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