当前位置: 首页>>代码示例>>PHP>>正文


PHP PHP_CodeSniffer_File::findPrevious方法代码示例

本文整理汇总了PHP中PHP_CodeSniffer_File::findPrevious方法的典型用法代码示例。如果您正苦于以下问题:PHP PHP_CodeSniffer_File::findPrevious方法的具体用法?PHP PHP_CodeSniffer_File::findPrevious怎么用?PHP PHP_CodeSniffer_File::findPrevious使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PHP_CodeSniffer_File的用法示例。


在下文中一共展示了PHP_CodeSniffer_File::findPrevious方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: process

 public function process(CodeSnifferFile $file, $stackPtr)
 {
     $tokens = $file->getTokens();
     $fileName = $file->getFilename();
     // Collect use statement aliases
     if ($tokens[$stackPtr]['code'] === T_USE) {
         /** function () use ($var) {} */
         $previousPtr = $file->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true);
         if ($tokens[$previousPtr]['code'] === T_CLOSE_PARENTHESIS) {
             return;
         }
         /** use Trait; */
         if ($file->findPrevious([T_CLASS, T_TRAIT], $stackPtr)) {
             return;
         }
         list($stackPtr, $namespaceAlias, $fullyQualifiedNamespace) = $this->getNamespace($stackPtr + 1, $file);
         if (!isset(static::$aliases[$fileName])) {
             static::$aliases[$fileName] = [];
         }
         static::$aliases[$fileName][] = $namespaceAlias;
         return;
     }
     // Check if aliased exist for caught exceptions
     $catchPtr = $tokens[$stackPtr]['parenthesis_opener'] + 1;
     $exceptionPtr = $file->findNext([T_CLASS, T_INTERFACE], $catchPtr, $tokens[$stackPtr]['parenthesis_closer'], true);
     $exceptionName = $tokens[$exceptionPtr]['content'];
     if (!in_array($exceptionName, static::$aliases[$fileName], false)) {
         $file->addError(sprintf('Trying to catch an undefined exception. Please add use-statement for "%s"', $exceptionName), $exceptionPtr);
     }
 }
开发者ID:internations,项目名称:kodierungsregelwerksammlung,代码行数:30,代码来源:CatchUndefinedExceptionSniff.php

示例2: process

 /**
  * Processes this test, when one of its tokens is encountered.
  *
  * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the 
  *        document
  * @param int $stackPtr Position of the current token in the stack passed 
  *        in $tokens
  * @return void
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     switch ($tokens[$stackPtr]['type']) {
         case 'T_BOOLEAN_AND':
         case 'T_BOOLEAN_OR':
             $error = 'Operators && and || are not allowed, use AND and OR instead';
             $phpcsFile->addError($error, $stackPtr);
             break;
         default:
             $beforePtr = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true);
             $afterPtr = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
             if ($tokens[$afterPtr]['type'] == 'T_VARIABLE') {
                 switch ($tokens[$beforePtr]['type']) {
                     case 'T_STRING':
                         $beforePtr = $phpcsFile->findPrevious(T_WHITESPACE, $beforePtr - 1, null, true);
                         if ($tokens[$beforePtr]['type'] == 'T_OBJECT_OPERATOR') {
                             break;
                         }
                     case 'T_FALSE':
                     case 'T_TRUE':
                     case 'T_NULL':
                         $error = 'Variables should precede constants in comparison operations';
                         $phpcsFile->addError($error, $stackPtr);
                         break;
                 }
             }
             break;
     }
 }
开发者ID:kohana,项目名称:coding-standards,代码行数:39,代码来源:ComparisonOperatorSniff.php

示例3: process

 /**
  * Processes this sniff, 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)
 {
     $tokens = $phpcsFile->getTokens();
     if (substr($tokens[$stackPtr]['content'], 0, 2) !== '//') {
         return;
     }
     $commentLine = $tokens[$stackPtr]['line'];
     $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true);
     if ($tokens[$lastContent]['line'] !== $commentLine) {
         return;
     }
     if ($tokens[$lastContent]['code'] === T_CLOSE_CURLY_BRACKET) {
         return;
     }
     // Special case for JS files.
     if ($tokens[$lastContent]['code'] === T_COMMA || $tokens[$lastContent]['code'] === T_SEMICOLON) {
         $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, $lastContent - 1, null, true);
         if ($tokens[$lastContent]['code'] === T_CLOSE_CURLY_BRACKET) {
             return;
         }
     }
     $error = 'Comments may not appear after statements';
     $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found');
     if ($fix === true) {
         $phpcsFile->fixer->addNewlineBefore($stackPtr);
     }
 }
开发者ID:felix021,项目名称:myenv,代码行数:36,代码来源:PostStatementCommentSniff.php

示例4: process

 /**
  * Processes this sniff, 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)
 {
     $tokens = $phpcsFile->getTokens();
     $next = $phpcsFile->findNext(T_INLINE_HTML, $stackPtr + 1, null, true);
     if ($next !== false) {
         return;
     }
     $has_html = $phpcsFile->findPrevious(T_INLINE_HTML, $stackPtr - 1);
     $prev = $phpcsFile->findPrevious(T_OPEN_TAG, $stackPtr - 1);
     if ($has_html !== false && $prev !== false && $tokens[$prev]['line'] === $tokens[$stackPtr]['line']) {
         // allow closing tag for single line PHP blocks in HTML files
         return;
     }
     // We've found the last closing tag in the file so the only thing
     // potentially remaining is inline HTML. Now we need to figure out
     // whether or not it's just a bunch of whitespace.
     $content = '';
     for ($i = $stackPtr + 1; $i < $phpcsFile->numTokens; $i++) {
         $content .= $tokens[$i]['content'];
     }
     // Check if the remaining inline HTML is just whitespace.
     $content = trim($content);
     if (empty($content)) {
         $error = 'A closing tag is not permitted at the end of a PHP file';
         $phpcsFile->addError($error, $stackPtr, 'NotAllowed');
     }
 }
开发者ID:markbiek,项目名称:coding-standards,代码行数:36,代码来源:ClosingTagSniff.php

示例5: process

	/**
	 * 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)
	{
		$tokens = $phpcsFile->getTokens();

		$prev = $phpcsFile->findPrevious(T_SEMICOLON, ($stackPtr - 1));
		if ($prev === false) {
			return;
		}

		// Ignore multiple statements in a FOR condition.
		if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
			foreach ($tokens[$stackPtr]['nested_parenthesis'] as $bracket) {
				$owner = $tokens[$bracket]['parenthesis_owner'];
				if ($tokens[$owner]['code'] === T_FOR) {
					return;
				}
			}
		}

		if ($tokens[$prev]['line'] === $tokens[$stackPtr]['line']) {

			$prevOpen = $phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1));
			$nextEnd = $phpcsFile->findNext(T_CLOSE_TAG, ($stackPtr + 1));
			if ($tokens[$prevOpen]['line'] === $tokens[$stackPtr]['line'] && $tokens[$nextEnd]['line'] === $tokens[$stackPtr]['line']) {
				return; // Ignore if it is in a template (open and close tag in the same line)
			}
			else {
				$error = 'Each PHP statement must be on a line by itself';
				$phpcsFile->addWarning($error, $stackPtr);
				return;
			}
		}

	}//end process()
开发者ID:BackupTheBerlios,项目名称:viscacha-svn,代码行数:43,代码来源:DisallowMultipleStatementsSniff.php

示例6: process

 /**
  * Process the sniff. Will be engaged when one of the tokens from ::register() is encountered.
  *
  * @param PHP_CodeSniffer_File $phpcsFile An instance of the current source file being scanned.
  * @param int $stackPtr The position of the encountered token in the provided file.
  * @return void
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     // Nothing to do if the file is already in the global namespace.
     if ($phpcsFile->findPrevious(T_NAMESPACE, $stackPtr) === false) {
         return;
     }
     // Only proceed with checking the matched namespaced string if is not part of a `namespace Vendor\Foo;` or a `use Vendor\Bar as Baz;` statement.
     if ($phpcsFile->findPrevious([T_NAMESPACE, T_USE], $stackPtr - 1, null, false, null, true) === false) {
         $nextNonClassSegment = $phpcsFile->findNext([T_NS_SEPARATOR, T_STRING], $stackPtr + 1, null, true);
         $lastNsSeperator = $phpcsFile->findPrevious(T_NS_SEPARATOR, $nextNonClassSegment);
         // Only report for the last backslash matched in a single namespace string. (This sniff will trigger on each slash from `new \Some\Vendor\Lib();`, so this makes sure we don't report 3 errors for that same statement.)
         if ($lastNsSeperator === $stackPtr) {
             $start = $phpcsFile->findPrevious([T_NS_SEPARATOR, T_STRING], $stackPtr - 1, null, true) + 1;
             $end = $phpcsFile->findNext([T_NS_SEPARATOR, T_STRING], $start + 1, null, true);
             $class = '';
             for ($i = $start; $i < $end; $i++) {
                 $class .= $tokens[$i]['content'];
             }
             $tClass = $phpcsFile->findPrevious(T_CLASS, $stackPtr - 1);
             // Check if the code is attempting to extend a class with the same name.
             if ($tClass !== false) {
                 $newClass = $phpcsFile->findNext(T_STRING, $tClass);
                 if ($tokens[$newClass]['content'] == $tokens[$end - 1]['content']) {
                     return;
                 }
                 $err = 'Namespaced class (%s) must be imported before use.';
                 $data = [$class];
                 $phpcsFile->addError($err, $stackPtr, 'ClassMustBeImported', $data);
             }
         }
     }
 }
开发者ID:loadsys,项目名称:loadsys_codesniffer,代码行数:40,代码来源:ClassesMustBeImportedSniff.php

示例7: processTokenWithinScope

 /**
  * Processes the function tokens within the class.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
  * @param int                  $stackPtr  The position where the token was found.
  * @param int                  $currScope The current scope opener token.
  *
  * @return void
  */
 protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
 {
     $tokens = $phpcsFile->getTokens();
     $methodName = $phpcsFile->getDeclarationName($stackPtr);
     if ($methodName === null) {
         // Ignore closures.
         return;
     }
     $modifier = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$scopeModifiers, $stackPtr);
     if ($modifier === false || $tokens[$modifier]['line'] !== $tokens[$stackPtr]['line']) {
         $error = 'Visibility must be declared on method "%s"';
         $data = array($methodName);
         $previous = $phpcsFile->findPrevious(array(T_WHITESPACE), $stackPtr - 1, null, true);
         // Only correct the trivial cases for now
         if (!$modifier && $tokens[$modifier]['line'] === $tokens[$stackPtr]['line']) {
             $phpcsFile->addFixableError($error, $stackPtr, 'Missing', $data);
             $visbility = 'public';
             $name = substr($tokens[$stackPtr]['content'], 1);
             $totalUnderscores = 0;
             while (strpos($name, '_') === 0) {
                 $totalUnderscores++;
                 $name = substr($name, 1);
             }
             if ($totalUnderscores > 1) {
                 $visbility = 'private';
             } elseif ($totalUnderscores > 0) {
                 $visbility = 'protected';
             }
         } else {
             $phpcsFile->addError($error, $stackPtr, 'Missing', $data);
         }
         //TODO
     }
 }
开发者ID:dereuromark,项目名称:cakephp-codesniffer,代码行数:43,代码来源:MethodScopeSniff.php

示例8: process

 /**
  * @param \PHP_CodeSniffer_File $phpcsFile
  * @param int $stackPtr
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $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;
         }
     }
     if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG && $tokens[$commentEnd]['code'] !== T_COMMENT) {
         if (array_key_exists('scope_opener', $tokens[$stackPtr]) && $this->functionHasReturn($phpcsFile, $stackPtr)) {
             $phpcsFile->addError('Function has return keyword but no doc block', $stackPtr);
             return;
         }
         if ($this->functionHasParams($phpcsFile, $stackPtr)) {
             $phpcsFile->addError('Function has parameters but no doc block', $stackPtr);
         }
     }
 }
开发者ID:graze,项目名称:standards,代码行数:30,代码来源:MissingFunctionCommentSniff.php

示例9: process

 /**
  * 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)
 {
     $tokens = $phpcsFile->getTokens();
     $prev = $phpcsFile->findPrevious(T_SEMICOLON, $stackPtr - 1);
     if ($prev === false) {
         return;
     }
     // Ignore multiple statements in a FOR condition.
     if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
         foreach ($tokens[$stackPtr]['nested_parenthesis'] as $bracket) {
             if (isset($tokens[$bracket]['parenthesis_owner']) === false) {
                 // Probably a closure sitting inside a function call.
                 continue;
             }
             $owner = $tokens[$bracket]['parenthesis_owner'];
             if ($tokens[$owner]['code'] === T_FOR) {
                 return;
             }
         }
     }
     if ($tokens[$prev]['line'] === $tokens[$stackPtr]['line']) {
         $inline_html = $phpcsFile->findPrevious(T_INLINE_HTML, $stackPtr - 1);
         if ($inline_html !== false && $tokens[$inline_html]['line'] === $tokens[$stackPtr]['line']) {
             return;
         }
         $error = 'Each PHP statement must be on a line by itself';
         $phpcsFile->addError($error, $stackPtr, 'SameLine');
         return;
     }
 }
开发者ID:markbiek,项目名称:coding-standards,代码行数:39,代码来源:DisallowMultipleStatementsSniff.php

示例10: processMemberVar

 /**
  * Processes the function tokens within the class.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
  * @param int                  $stackPtr  The position where the token was found.
  *
  * @return void
  */
 protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $modifier = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$scopeModifiers, $stackPtr);
     if ($modifier === false || $tokens[$modifier]['line'] !== $tokens[$stackPtr]['line']) {
         $error = 'Scope modifier not specified for member variable "%s"';
         $previous = $phpcsFile->findPrevious(array(T_WHITESPACE), $stackPtr - 1, null, true);
         $data = array($tokens[$stackPtr]['content']);
         if ($previous && $tokens[$previous]['code'] === T_VAR) {
             $phpcsFile->addFixableError($error, $stackPtr, 'Missing', $data);
             if ($phpcsFile->fixer->enabled === true) {
                 $visbility = 'public';
                 $name = substr($tokens[$stackPtr]['content'], 1);
                 $totalUnderscores = 0;
                 while (strpos($name, '_') === 0) {
                     $totalUnderscores++;
                     $name = substr($name, 1);
                 }
                 if ($totalUnderscores > 1) {
                     $visbility = 'private';
                 } elseif ($totalUnderscores > 0) {
                     $visbility = 'protected';
                 }
                 $phpcsFile->fixer->replaceToken($previous, $visbility);
             }
         } else {
             $phpcsFile->addError($error, $stackPtr, 'Missing', $data);
         }
     }
 }
开发者ID:dereuromark,项目名称:cakephp-codesniffer,代码行数:38,代码来源:MemberVarScopeSniff.php

示例11: process

 /**
  * 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)
 {
     $tokens = $phpcsFile->getTokens();
     $tokenizer = $phpcsFile->tokenizerType;
     $openBracket = $tokens[$stackPtr]['parenthesis_opener'];
     $closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
     if ($tokens[$stackPtr]['code'] === T_FOR) {
         // We only want to check the condition in FOR loops.
         $start = $phpcsFile->findNext(T_SEMICOLON, $openBracket + 1);
         $end = $phpcsFile->findPrevious(T_SEMICOLON, $closeBracket - 1);
     } else {
         $start = $openBracket;
         $end = $closeBracket;
     }
     for ($i = $start + 1; $i < $end; $i++) {
         if ($tokens[$i]['code'] === T_STRING && in_array($tokens[$i]['content'], $this->forbiddenFunctions[$tokenizer])) {
             $functionName = $tokens[$i]['content'];
             if ($tokenizer === 'JS') {
                 // Needs to be in the form object.function to be valid.
                 $prev = $phpcsFile->findPrevious(T_WHITESPACE, $i - 1, null, true);
                 if ($prev === false || $tokens[$prev]['code'] !== T_OBJECT_OPERATOR) {
                     continue;
                 }
                 $functionName = 'object.' . $functionName;
             } else {
                 $functionName .= '()';
             }
             $error = 'The use of %s inside a loop condition is not allowed; assign the return value to a variable and use the variable in the loop condition instead';
             $data = array($functionName);
             $phpcsFile->addError($error, $i, 'Found', $data);
         }
         //end if
     }
     //end for
 }
开发者ID:ravivare,项目名称:moodle-local_codechecker,代码行数:44,代码来源:DisallowSizeFunctionsInLoopsSniff.php

示例12: process

 /**
  * Processes this test, when one of its tokens is encountered.
  *
  * @param PHP_CodeSniffer_File $phpcsFile
  * @param int $stackPtr
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $functionToken = $phpcsFile->findNext(T_FUNCTION, $stackPtr);
     if ($functionToken === false) {
         return;
     }
     $nameToken = $phpcsFile->findNext(T_STRING, $functionToken);
     if (in_array($tokens[$nameToken]['content'], $this->magicMethods) === false) {
         return;
     }
     $scopeToken = $phpcsFile->findPrevious(array(T_PUBLIC, T_PROTECTED, T_PRIVATE), $nameToken, $stackPtr);
     if ($scopeToken === false) {
         return;
     }
     if ($tokens[$scopeToken]['type'] != 'T_PUBLIC') {
         $error = "Magic methods must be public (since PHP 5.3) !";
         $phpcsFile->addError($error, $stackPtr);
     }
     $staticToken = $phpcsFile->findPrevious(T_STATIC, $scopeToken, $scopeToken - 2);
     if ($staticToken === false) {
         return;
     } else {
         $error = "Magic methods can not be static (since PHP 5.3) !";
         $phpcsFile->addError($error, $stackPtr);
     }
 }
开发者ID:jonasdekeukelaere,项目名称:dotfiles-1,代码行数:33,代码来源:NonStaticMagicMethodsSniff.php

示例13: process

 /**
  * Processes the tokens that this sniff is interested in.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
  * @param int                  $stackPtr  The position in the stack where
  *                                        the token was found.
  *
  * @return void
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $utils = Security_Sniffs_UtilsFactory::getInstance();
     $tokens = $phpcsFile->getTokens();
     if ($tokens[$stackPtr]['content'] == "'#value'" || $tokens[$stackPtr]['content'] == '"#value"') {
         $closer = $phpcsFile->findNext(T_SEMICOLON, $stackPtr);
         $next = $phpcsFile->findNext(array_merge(PHP_CodeSniffer_Tokens::$bracketTokens, PHP_CodeSniffer_Tokens::$emptyTokens, PHP_CodeSniffer_Tokens::$assignmentTokens), $stackPtr + 1, $closer + 1, true);
         if ($next == $closer && $tokens[$next]['code'] == T_SEMICOLON) {
             // Case of $label = $element['#value'];
             $next = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$assignmentTokens, $next);
             $next = $phpcsFile->findPrevious(T_VARIABLE, $next);
             $phpcsFile->addWarning('Potential XSS found with #value on ' . $tokens[$next]['content'], $next, 'D7XSSWarFormValue');
         } elseif ($next && $utils::is_token_user_input($tokens[$next])) {
             $phpcsFile->addError('XSS found with #value on ' . $tokens[$next]['content'], $next, 'D7XSSErrFormValue');
         } elseif ($next && PHP_CodeSniffer::getConfigData('ParanoiaMode')) {
             if (in_array($tokens[$next]['content'], $utils::getXSSMitigationFunctions())) {
                 $n = $phpcsFile->findNext($utils::getVariableTokens(), $next + 1, $closer);
                 if ($n) {
                     $phpcsFile->addWarning('Potential XSS found with #value on ' . $tokens[$n]['content'], $n, 'D7XSSWarFormValue');
                 }
             } else {
                 $phpcsFile->addWarning('Potential XSS found with #value on ' . $tokens[$next]['content'], $next, 'D7XSSWarFormValue');
             }
         }
     }
 }
开发者ID:valugi,项目名称:phpcs-security-audit,代码行数:35,代码来源:XSSFormValueSniff.php

示例14: process

 /**
  * @inheritdoc
  */
 public function process(\PHP_CodeSniffer_File $phpCsFile, $stackPointer)
 {
     $tokens = $phpCsFile->getTokens();
     $prevIndex = $phpCsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPointer - 1, null, true);
     if (!in_array($tokens[$prevIndex]['code'], [T_TRUE, T_FALSE, T_NULL, T_LNUMBER, T_CONSTANT_ENCAPSED_STRING])) {
         return;
     }
     $leftIndexEnd = $prevIndex;
     $leftIndexStart = $prevIndex;
     $prevIndex = $phpCsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, $prevIndex - 1, null, true);
     if (!$prevIndex) {
         return;
     }
     if ($this->isGivenKind(PHP_CodeSniffer_Tokens::$arithmeticTokens, $tokens[$prevIndex])) {
         return;
     }
     if ($this->isGivenKind([T_STRING_CONCAT], $tokens[$prevIndex])) {
         return;
     }
     $fixable = true;
     $error = 'Usage of Yoda conditions is not allowed. Switch the expression order.';
     $prevContent = $tokens[$prevIndex]['content'];
     if (!$this->isGivenKind(PHP_CodeSniffer_Tokens::$assignmentTokens, $tokens[$prevIndex]) && !$this->isGivenKind(PHP_CodeSniffer_Tokens::$booleanOperators, $tokens[$prevIndex]) && $prevContent !== '(') {
         // Not fixable
         $phpCsFile->addError($error, $stackPointer);
         return;
     }
     //TODO
 }
开发者ID:spryker,项目名称:code-sniffer,代码行数:32,代码来源:ConditionalExpressionOrderSniff.php

示例15: process

 /**
  * 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)
 {
     $tokens = $phpcsFile->getTokens();
     $token = $tokens[$stackPtr];
     // exclude function definitions, class methods, and namespaced calls
     if ($token['code'] == T_STRING && ($prev = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true)) && (in_array($tokens[$prev]['code'], array(T_FUNCTION, T_DOUBLE_COLON, T_OBJECT_OPERATOR)) || $tokens[$prev]['code'] == T_NS_SEPARATOR && ($pprev = $phpcsFile->findPrevious(T_WHITESPACE, $prev - 1, null, true)) && $tokens[$pprev]['code'] == T_STRING)) {
         return;
     }
     $exclude = explode(',', $this->exclude);
     $groups = $this->getGroups();
     if (empty($groups)) {
         return;
     }
     foreach ($groups as $groupName => $group) {
         if (in_array($groupName, $exclude)) {
             continue;
         }
         $functions = implode('|', $group['functions']);
         $functions = preg_replace('#[^\\.]\\*#', '.*', $functions);
         // So you can use * instead of .*
         if (preg_match('#\\b(' . $functions . ')\\b#', $token['content']) < 1) {
             continue;
         }
         if ($group['type'] == 'warning') {
             $addWhat = array($phpcsFile, 'addWarning');
         } else {
             $addWhat = array($phpcsFile, 'addError');
         }
         call_user_func($addWhat, $group['message'], $stackPtr, $groupName, array($token['content']));
     }
 }
开发者ID:chrux,项目名称:WordPress-Coding-Standards,代码行数:40,代码来源:FunctionRestrictionsSniff.php


注:本文中的PHP_CodeSniffer_File::findPrevious方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。