/** * Processes this test, when one of its tokens is encountered. * * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. * @param int $stackPtr The position of the current token * in the stack passed in $tokens. * * @return void */ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { if (false === ($commentEnd = $phpcsFile->findPrevious(array(T_COMMENT, T_DOC_COMMENT, T_CLASS, T_FUNCTION, T_OPEN_TAG), $stackPtr - 1))) { return; } parent::process($phpcsFile, $stackPtr); }
/** * Processes this test, when one of its tokens is encountered. * * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. * @param int $stackPtr The position of the current token * in the stack passed in $tokens. * * @return void */ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { if (false === ($commentEnd = $phpcsFile->findPrevious(array(T_COMMENT, T_DOC_COMMENT, T_CLASS, T_FUNCTION, T_OPEN_TAG), $stackPtr - 1))) { return; } $tokens = $phpcsFile->getTokens(); $code = $tokens[$commentEnd]['code']; $name = $phpcsFile->getDeclarationName($stackPtr); $commentRequired = strpos($name, 'test') !== 0 && $name !== 'setUp'; if ($code === T_COMMENT && !$commentRequired || $code !== T_DOC_COMMENT && !$commentRequired) { return; } parent::process($phpcsFile, $stackPtr); }
/** * {@inheritdoc} */ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { if (false === ($commentEnd = $phpcsFile->findPrevious(array(T_COMMENT, T_DOC_COMMENT, T_CLASS, T_FUNCTION, T_OPEN_TAG), $stackPtr - 1))) { return; } $tokens = $phpcsFile->getTokens(); $code = $tokens[$commentEnd]['code']; $method = $phpcsFile->getMethodProperties($stackPtr); $commentRequired = $this->isRequiredScope($method['scope']); if ($code === T_COMMENT && !$commentRequired || $code !== T_DOC_COMMENT && !$commentRequired) { return; } parent::process($phpcsFile, $stackPtr); }
/** * Processes this test, when one of its tokens is encountered. * * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. * @param int $stackPtr The position of the current token * in the stack passed in $tokens. * * @return void */ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { if (false === ($commentEnd = $phpcsFile->findPrevious(array(T_COMMENT, T_DOC_COMMENT, T_CLASS, T_FUNCTION, T_OPEN_TAG), $stackPtr - 1))) { return; } $tokens = $phpcsFile->getTokens(); $code = $tokens[$commentEnd]['code']; // a comment is not required on protected/private methods $method = $phpcsFile->getMethodProperties($stackPtr); $commentRequired = in_array($method['scope'], array('public', 'protected', 'private')); if ($code === T_COMMENT && !$commentRequired || $code !== T_DOC_COMMENT && !$commentRequired) { return; } parent::process($phpcsFile, $stackPtr); }
/** * Processes this test, when one of its tokens is encountered. * * @param PHP_CodeSniffer_File $phpcsFile The current file being processed. * @param int $stackPtr The position of the current token * in the stack passed in $tokens. * * @return void */ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $nextReturn = $phpcsFile->findNext(T_RETURN, $stackPtr); $nextFunction = $phpcsFile->findNext(T_FUNCTION, $stackPtr + 1); // Ignore functions without return type $this->hasReturn = !($nextReturn === false || $nextReturn > $nextFunction); $parameters = $phpcsFile->getMethodParameters($stackPtr); $find = PHP_CodeSniffer_Tokens::$methodPrefixes; $find[] = T_WHITESPACE; $commentEnd = $phpcsFile->findPrevious($find, $stackPtr - 1, null, true); if ($tokens[$commentEnd]['code'] === T_COMMENT) { // Inline comments might just be closing comments for // control structures or functions instead of function comments // using the wrong comment type. If there is other code on the line, // assume they relate to that code. $prev = $phpcsFile->findPrevious($find, $commentEnd - 1, null, true); if ($prev !== false && $tokens[$prev]['line'] === $tokens[$commentEnd]['line']) { $commentEnd = $prev; } } // we only require the doc for methods with either a return value or parameters // However if we don't have any of it but a doc block is created we still want to check it if (!$this->hasReturn && empty($parameters)) { if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG && $tokens[$commentEnd]['code'] !== T_COMMENT) { return; } } $commentStart = 0; if (isset($tokens[$commentEnd]['comment_opener'])) { $commentStart = $tokens[$commentEnd]['comment_opener']; } if ($this->isValidInheritationComment($phpcsFile, $commentStart, $commentEnd)) { return; } parent::process($phpcsFile, $stackPtr); if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG) { return; } $this->processNewLine($phpcsFile, $commentStart); }