properties - PHP CodeSniffer property not recognized -
properties - PHP CodeSniffer property not recognized -
my sniff doesn't work , doesn't recognize property private $testvar. want create doc-block mandatory there.
when run code sniffer, process method doesn't seem used. added echos there before.
does token t_property exist? cannot find on php manual http://php.net/manual/en/tokens.php yet, in squiz lab source code t_property used.
<?php /** * extension pear class comment sniff. * */ /** * extension pear class comment sniff. * */ class xyz_sniffs_commenting_propertycommentsniff implements php_codesniffer_sniff { private $testvar = 1; /** * returns array of tokens test wants hear for. * * @return array */ public function register() { homecoming array(t_property); } /** * checks property comments. * * @param php_codesniffer_file $phpcsfile file object * @param int $stackptr stack pointer * * @return void */ public function process(php_codesniffer_file $phpcsfile, $stackptr) { $tokens = $phpcsfile->gettokens(); $find = php_codesniffer_tokens::$scopemodifiers; $find[] = t_whitespace; $find[] = t_static; $commentend = $phpcsfile->findprevious($find, ($stackptr - 1), null, true); if ($tokens[$commentend]['code'] !== t_doc_comment_close_tag && $tokens[$commentend]['code'] !== t_comment ) { $phpcsfile->adderror('missing property doc comment', $stackptr, 'missing'); $phpcsfile->recordmetric($stackptr, 'function has property comment', 'no'); return; } else { $phpcsfile->recordmetric($stackptr, 'function has property comment', 'yes'); } } }
thanks help :).
the t_property token used when checking javascript files. doesn't exist php files.
for php files, you'll want utilize abstractvariablesniff helper. here sniff checks comments of fellow member vars: https://github.com/squizlabs/php_codesniffer/blob/master/codesniffer/standards/squiz/sniffs/commenting/variablecommentsniff.php
notice how extends php_codesniffer_standards_abstractvariablesniff , implements processmembervar() method. leaves processvariable() , processvariableinstring() methods empty because doesn't care regular variables within code.
also note if writing commenting sniffs, comment parser different in 2.0 version (currently in beta due go stable week now). take @ new version of above sniff here: https://github.com/squizlabs/php_codesniffer/blob/phpcs-fixer/codesniffer/standards/squiz/sniffs/commenting/variablecommentsniff.php
php properties token codesniffer sniffer
Comments
Post a Comment