/** * @param PHP_CodeSniffer_File $phpcsFile * @param mixed[] $tokens * @param integer $methodTokenPointer * @return integer|null */ private function findVisibilityModifier(PHP_CodeSniffer_File $phpcsFile, array $tokens, $methodTokenPointer) { $visibilityModifiedTokenPointer = TokenHelper::findPreviousNonWhitespace($phpcsFile, $methodTokenPointer - 1); $visibilityModifiedToken = $tokens[$visibilityModifiedTokenPointer]; if (in_array($visibilityModifiedToken['code'], [T_PUBLIC, T_PROTECTED, T_PRIVATE], true)) { return $visibilityModifiedToken['code']; } elseif (in_array($visibilityModifiedToken['code'], [T_ABSTRACT, T_STATIC], true)) { return $this->findVisibilityModifier($phpcsFile, $tokens, $visibilityModifiedTokenPointer); } return null; }
/** * @param \PHP_CodeSniffer_File $phpcsFile * @param integer $startPointer * @return boolean */ private static function isReferencedName(PHP_CodeSniffer_File $phpcsFile, $startPointer) { $tokens = $phpcsFile->getTokens(); $previousPointer = TokenHelper::findPreviousNonWhitespace($phpcsFile, $startPointer - 1); $previousToken = $tokens[$previousPointer]; $skipTokenCodes = [T_FUNCTION, T_AS, T_DOUBLE_COLON, T_OBJECT_OPERATOR, T_NAMESPACE]; if ($previousToken['code'] === T_USE) { $classPointer = $phpcsFile->findPrevious(T_CLASS, $startPointer - 1); if ($classPointer !== false) { $tokens = $phpcsFile->getTokens(); $classToken = $tokens[$classPointer]; return $startPointer > $classToken['scope_opener'] && $startPointer < $classToken['scope_closer']; } return false; } return !in_array($previousToken['code'], array_merge($skipTokenCodes, TokenHelper::$typeKeywordTokenCodes), true); }