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


PHP PHP_CodeSniffer_File::hasCondition方法代码示例

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


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

示例1: processVariable

 /**
  * 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
  */
 protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $varName = ltrim($tokens[$stackPtr]['content'], '$');
     $phpReservedVars = array('_SERVER', '_GET', '_POST', '_REQUEST', '_SESSION', '_ENV', '_COOKIE', '_FILES', 'GLOBALS', 'http_response_header', 'HTTP_RAW_POST_DATA', 'php_errormsg');
     // If it's a php reserved var, then its ok.
     if (in_array($varName, $phpReservedVars) === true) {
         return;
     }
     // There is no way for us to know if the var is public or private,
     // so we have to ignore a leading underscore if there is one and just
     // check the main part of the variable name.
     $originalVarName = $varName;
     if (substr($varName, 0, 1) === '_') {
         $objOperator = $phpcsFile->findPrevious(array(T_WHITESPACE), $stackPtr - 1, null, true);
         if ($tokens[$objOperator]['code'] === T_DOUBLE_COLON) {
             // The variable lives within a class, and is referenced like
             // this: MyClass::$_variable, so we don't know its scope.
             $inClass = true;
         } else {
             $inClass = $phpcsFile->hasCondition($stackPtr, array(T_CLASS, T_INTERFACE, T_TRAIT));
         }
         if ($inClass === true) {
             $varName = substr($varName, 1);
         }
     }
     if (PHP_CodeSniffer::isCamelCaps($varName, false, true, false) === false) {
         $error = 'Variable "%s" is not in valid camel caps format';
         $data = array($originalVarName);
         $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $data);
     }
 }
开发者ID:wikidi,项目名称:codesniffer,代码行数:41,代码来源:ValidVariableNameSniff.php

示例2: process

 /**
  * Processes this test, when one of its tokens is encountered.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
  * @param integer $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 (isset($tokens[$stackPtr]['scope_closer']) === false) {
         // Probably an interface method.
         return;
     }
     $closeBrace = $tokens[$stackPtr]['scope_closer'];
     $prevContent = $phpcsFile->findPrevious(T_WHITESPACE, $closeBrace - 1, null, true);
     $braceLine = $tokens[$closeBrace]['line'];
     $prevLine = $tokens[$prevContent]['line'];
     $found = $braceLine - $prevLine - 1;
     if ($phpcsFile->hasCondition($stackPtr, T_FUNCTION) === true || isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
         // Nested function.
         if ($found < 0) {
             $error = 'Closing brace of nested function must be on a new line';
             $phpcsFile->addError($error, $closeBrace, 'ContentBeforeClose');
         } elseif ($found > 0) {
             $error = 'Expected 0 blank lines before closing brace of nested function; %s found';
             $data = array($found);
             $phpcsFile->addError($error, $closeBrace, 'SpacingBeforeNestedClose', $data);
         }
     } else {
         if ($found !== 0) {
             $error = 'Expected 0 blank lines before closing function brace; %s found';
             $data = array($found);
             $phpcsFile->addError($error, $closeBrace, 'SpacingBeforeClose', $data);
         }
     }
 }
开发者ID:ciricihq,项目名称:cirici-codesniffer,代码行数:38,代码来源:FunctionClosingBraceSpaceSniff.php

示例3: 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
  * @see PHP_CodeSniffer_Sniff::process()
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $token = $tokens[$stackPtr]['content'];
     // Only accept class member functions
     if (false === $phpcsFile->hasCondition($stackPtr, T_CLASS)) {
         return;
     }
     $nextTokenIndex = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true);
     $methodName = $tokens[$nextTokenIndex]['content'];
     $methodProperties = $phpcsFile->getMethodProperties($stackPtr);
     switch ($methodName) {
         case '__call':
             $this->_checkCall($phpcsFile, $stackPtr, $methodName, $methodProperties);
             break;
         case '__get':
             $this->_checkGet($phpcsFile, $stackPtr, $methodName, $methodProperties);
             break;
         case '__isset':
             $this->_checkIsset($phpcsFile, $stackPtr, $methodName, $methodProperties);
             break;
         case '__set':
             $this->_checkSet($phpcsFile, $stackPtr, $methodName, $methodProperties);
             break;
         case '__toString':
             $this->_checkToString($phpcsFile, $stackPtr, $methodName, $methodProperties);
             break;
         case '__unset':
             $this->_checkUnset($phpcsFile, $stackPtr, $methodName, $methodProperties);
             break;
         default:
             break;
     }
 }
开发者ID:foobugs-standards,项目名称:php52to53,代码行数:44,代码来源:MagicMethodsSniff.php

示例4: 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;
     }
     if ($phpcsFile->hasCondition($stackPtr, T_FUNCTION) === true) {
         // Ignore nested functions.
         return;
     }
     $modifier = null;
     for ($i = $stackPtr - 1; $i > 0; $i--) {
         if ($tokens[$i]['line'] < $tokens[$stackPtr]['line']) {
             break;
         } else {
             if (isset(PHP_CodeSniffer_Tokens::$scopeModifiers[$tokens[$i]['code']]) === true) {
                 $modifier = $i;
                 break;
             }
         }
     }
     if ($modifier === null) {
         $error = 'Visibility must be declared on method "%s"';
         $data = array($methodName);
         $phpcsFile->addError($error, $stackPtr, 'Missing', $data);
     }
 }
开发者ID:squizlabs,项目名称:php_codesniffer,代码行数:38,代码来源:MethodScopeSniff.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();
     if ($phpcsFile->hasCondition($stackPtr, T_FUNCTION) === true) {
         $error = 'The use of inner functions is forbidden';
         $phpcsFile->addError($error, $stackPtr);
     }
 }
开发者ID:resid,项目名称:PHP_CodeSniffer,代码行数:17,代码来源:InnerFunctionsSniff.php

示例6: _shouldIgnoreUse

 /**
  * Check if this use statement is part of the namespace block.
  *
  * @param PHP_CodeSniffer_File $phpcsFile
  * @param int $stackPtr
  * @return bool
  */
 private function _shouldIgnoreUse(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     // keyword inside closure
     $next = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, NULL, TRUE);
     if ($tokens[$next]['code'] === T_OPEN_PARENTHESIS) {
         return TRUE;
     }
     // use trait in class
     if ($phpcsFile->hasCondition($stackPtr, T_CLASS) === TRUE) {
         return TRUE;
     }
     // use trait in trait
     if ($phpcsFile->hasCondition($stackPtr, T_TRAIT) === TRUE) {
         return TRUE;
     }
     return FALSE;
 }
开发者ID:mikulas,项目名称:code-sniffs,代码行数:25,代码来源:UseNewlinesSniff.php

示例7: 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();
     if ($tokens[$stackPtr]['code'] === T_FUNCTION) {
         $methodProps = $phpcsFile->getMethodProperties($stackPtr);
         // Abstract methods do not require a closing comment.
         if ($methodProps['is_abstract'] === true) {
             return;
         }
         // Closures do not require a closing comment.
         if ($methodProps['is_closure'] === true) {
             return;
         }
         // If this function is in an interface then we don't require
         // a closing comment.
         if ($phpcsFile->hasCondition($stackPtr, T_INTERFACE) === true) {
             return;
         }
         if (isset($tokens[$stackPtr]['scope_closer']) === false) {
             $error = 'Possible parse error: non-abstract method defined as abstract';
             $phpcsFile->addWarning($error, $stackPtr);
             return;
         }
         $decName = $phpcsFile->getDeclarationName($stackPtr);
         $comment = '//end ' . $decName . '()';
     } else {
         if ($tokens[$stackPtr]['code'] === T_CLASS) {
             $comment = '//end class';
         } else {
             $comment = '//end interface';
         }
     }
     //end if
     if (isset($tokens[$stackPtr]['scope_closer']) === false) {
         $error = 'Possible parse error: ';
         $error .= $tokens[$stackPtr]['content'];
         $error .= ' missing opening or closing brace';
         $phpcsFile->addWarning($error, $stackPtr);
         return;
     }
     $closingBracket = $tokens[$stackPtr]['scope_closer'];
     if ($closingBracket === null) {
         // Possible inline structure. Other tests will handle it.
         return;
     }
     $error = 'Expected ' . $comment;
     if (isset($tokens[$closingBracket + 1]) === false || $tokens[$closingBracket + 1]['code'] !== T_COMMENT) {
         $phpcsFile->addError($error, $closingBracket);
         return;
     }
     if (rtrim($tokens[$closingBracket + 1]['content']) !== $comment) {
         $phpcsFile->addError($error, $closingBracket);
         return;
     }
 }
开发者ID:resid,项目名称:PHP_CodeSniffer,代码行数:64,代码来源:ClosingDeclarationCommentSniff.php

示例8: 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();
     if (isset($tokens[$stackPtr]['scope_opener']) === false) {
         // Probably an interface method.
         return;
     }
     $openBrace = $tokens[$stackPtr]['scope_opener'];
     $nextContent = $phpcsFile->findNext(T_WHITESPACE, $openBrace + 1, null, true);
     if ($nextContent === $tokens[$stackPtr]['scope_closer']) {
         // The next bit of content is the closing brace, so this
         // is an empty function and should have a blank line
         // between the opening and closing braces.
         return;
     }
     $braceLine = $tokens[$openBrace]['line'];
     $nextLine = $tokens[$nextContent]['line'];
     $found = $nextLine - $braceLine - 1;
     if ($found > 0) {
         $error = "Expected 0 blank lines after opening function brace; {$found} found";
         $phpcsFile->addError($error, $openBrace);
     }
     if ($phpcsFile->tokenizerType === 'JS') {
         // Do some additional checking before the function brace.
         $nestedFunction = $phpcsFile->hasCondition($stackPtr, T_FUNCTION) === true || isset($tokens[$stackPtr]['nested_parenthesis']) === true;
         $functionLine = $tokens[$tokens[$stackPtr]['parenthesis_closer']]['line'];
         $lineDifference = $braceLine - $functionLine;
         if ($nestedFunction === true) {
             if ($lineDifference > 0) {
                 $error = "Expected 0 blank lines before openning brace of nested function; {$found} found";
                 $phpcsFile->addError($error, $openBrace);
             }
         } else {
             if ($lineDifference === 0) {
                 $error = 'Opening brace should be on a new line';
                 $phpcsFile->addError($error, $openBrace);
                 return;
             }
             if ($lineDifference > 1) {
                 $ender = 'line';
                 if ($lineDifference - 1 !== 1) {
                     $ender .= 's';
                 }
                 $error = 'Opening brace should be on the line after the declaration; found ' . ($lineDifference - 1) . ' blank ' . $ender;
                 $phpcsFile->addError($error, $openBrace);
                 return;
             }
         }
         //end if
     }
     //end if
 }
开发者ID:josephj,项目名称:modev,代码行数:61,代码来源:FunctionOpeningBraceSpaceSniff.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();
     if ($phpcsFile->hasCondition($stackPtr, T_FUNCTION) === true) {
         $prev = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true);
         if ($tokens[$prev]['code'] === T_EQUAL) {
             // Ignore closures.
             return;
         }
         $error = 'The use of inner functions is forbidden';
         $phpcsFile->addError($error, $stackPtr, 'NotAllowed');
     }
 }
开发者ID:sakshika,项目名称:ATM,代码行数:22,代码来源:InnerFunctionsSniff.php

示例10: _shouldIgnoreUse

 /**
  * Check if this use statement is part of the namespace block.
  *
  * @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
  */
 private function _shouldIgnoreUse(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     // Ignore USE keywords inside closures.
     $next = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
     if ($tokens[$next]['code'] === T_OPEN_PARENTHESIS) {
         return true;
     }
     // Ignore USE keywords for traits.
     if ($phpcsFile->hasCondition($stackPtr, T_CLASS) === true) {
         return true;
     }
     return false;
 }
开发者ID:Skokan44,项目名称:csfd-api,代码行数:23,代码来源:UseDeclarationSniff.php

示例11: checkAvailableReturnStatement

 /**
  * This methods checks for return statements.
  *
  * If there is a doc comment like "@return void".
  * A forbidden return statement is in this context all return statement
  * expect "return;".
  * Like "return $foo;", "return 5;", "return null;", ...
  *
  * If there is a doc comment like "@return int", "@return bool", ...
  * A forbidden return statement is in this context "return;"
  * Because in a method with defined @return statement there must not be empty
  * return statements.
  *
  * @param array   $tokens     Token array of file
  * @param integer $tokenStart Integer, token number where the checks will begin
  * @param integer $tokenEnd   Integer, token number where the checks will end
  * @param bool    $nonEmpty   If true, function returns true if there is a
  *                            non empty return statement like "return $foo;"
  *                            If false, function returns true if there is
  *                            a empty return statement like "return;"
  *
  * @return bool
  */
 protected function checkAvailableReturnStatement(array $tokens, $tokenStart, $tokenEnd, $nonEmpty = true)
 {
     $returnStatementResult = false;
     do {
         $returnResult = null;
         $result = $this->currentFile->findNext(array(T_RETURN), $tokenStart, $tokenEnd);
         // If there is a return statement in this function / method, try to
         // find the next token, expect whitespaces.
         if ($result !== false) {
             $returnResult = $this->currentFile->findNext(array(T_WHITESPACE), $result + 1, $tokenEnd, true, null, true);
         }
         // If there is no return-Statement between $tokenStart and
         // $tokenEnd, stop here with the loop.
         if ($result === false) {
             $tokenStart = $tokenEnd;
             // If there is a return-Statement between $tokenStart and $tokenEnd,
             // check if the this return statement is part of an anonymous
             // functions. In this case, this will be ignored.
         } else {
             if ($nonEmpty === true && $this->currentFile->hasCondition($result, T_CLOSURE) === true) {
                 break;
                 // If there is a return-Statement between $tokenStart and $tokenEnd,
                 // check if the next relevant token is a T_SEMICOLON. If no, this
                 // is a normal return statement like "return $foo;".
             } else {
                 if ($nonEmpty === true && $result !== false && $returnResult !== false && $tokens[$returnResult]['code'] !== T_SEMICOLON) {
                     $returnStatementResult = true;
                     break;
                     // If there is a return-Statement between $tokenStart and $tokenEnd,
                     // check if the next relevant token is a T_SEMICOLON. If yes, this
                     // is a empty return statement like "return;".
                 } else {
                     if ($nonEmpty === false && $result !== false && $returnResult !== false && $tokens[$returnResult]['code'] === T_SEMICOLON) {
                         $returnStatementResult = true;
                         break;
                         // If no case is affected, raise the pointer :).
                     } else {
                         $tokenStart = $result + 1;
                     }
                 }
             }
         }
         //end if
     } while ($tokenStart < $tokenEnd);
     return $returnStatementResult;
 }
开发者ID:typo3-ci,项目名称:typo3sniffpool,代码行数:69,代码来源:AlwaysReturnSniff.php

示例12: 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();
     if (isset($tokens[$stackPtr]['scope_closer']) === false) {
         // Probably an interface method.
         return;
     }
     $closeBrace = $tokens[$stackPtr]['scope_closer'];
     $prevContent = $phpcsFile->findPrevious(T_WHITESPACE, $closeBrace - 1, null, true);
     // Special case for empty JS functions
     if ($phpcsFile->tokenizerType === 'JS' && $prevContent === $tokens[$stackPtr]['scope_opener']) {
         // In this case, the opening and closing brace must be
         // right next to each other.
         if ($tokens[$stackPtr]['scope_closer'] !== $tokens[$stackPtr]['scope_opener'] + 1) {
             $error = 'The opening and closing braces of empty functions must be directly next to each other; e.g., function () {}';
             $phpcsFile->addError($error, $closeBrace, 'SpacingBetween');
         }
         return;
     }
     $braceLine = $tokens[$closeBrace]['line'];
     $prevLine = $tokens[$prevContent]['line'];
     $found = $braceLine - $prevLine - 1;
     if ($phpcsFile->hasCondition($stackPtr, T_FUNCTION) === true || isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
         // Nested function.
         if ($found < 0) {
             $error = 'Closing brace of nested function must be on a new line';
             $phpcsFile->addError($error, $closeBrace, 'ContentBeforeClose');
         } else {
             if ($found > 0) {
                 $error = 'Expected 0 blank lines before closing brace of nested function; %s found';
                 $data = array($found);
                 $phpcsFile->addError($error, $closeBrace, 'SpacingBeforeNestedClose', $data);
             }
         }
     } else {
         if ($found !== 1) {
             $error = 'Expected 1 blank line before closing function brace; %s found';
             $data = array($found);
             $phpcsFile->addError($error, $closeBrace, 'SpacingBeforeClose', $data);
         }
     }
 }
开发者ID:SebFav,项目名称:ApplicationInternet2,代码行数:51,代码来源:FunctionClosingBraceSpaceSniff.php

示例13: 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();
     $className = $stackPtr - 1;
     if ($tokens[$className]['code'] === T_SELF) {
         if (strtolower($tokens[$className]['content']) !== $tokens[$className]['content']) {
             $error = 'Must use "self::" for local static member reference; found "%s::"';
             $data = array($tokens[$className]['content']);
             $phpcsFile->addError($error, $className, 'IncorrectCase', $data);
             return;
         }
     } else {
         if ($tokens[$className]['code'] === T_STRING) {
             // Make sure this is another class reference.
             $declarationName = $phpcsFile->getDeclarationName($currScope);
             if ($declarationName === $tokens[$className]['content']) {
                 // Class name is the same as the current class, which is not allowed
                 // except if being used inside a closure.
                 if ($phpcsFile->hasCondition($stackPtr, T_CLOSURE) === false) {
                     $error = 'Must use "self::" for local static member reference';
                     $phpcsFile->addError($error, $className, 'NotUsed');
                     return;
                 }
             }
         }
     }
     if ($tokens[$stackPtr - 1]['code'] === T_WHITESPACE) {
         $found = strlen($tokens[$stackPtr - 1]['content']);
         $error = 'Expected 0 spaces before double colon; %s found';
         $data = array($found);
         $phpcsFile->addError($error, $className, 'SpaceBefore', $data);
     }
     if ($tokens[$stackPtr + 1]['code'] === T_WHITESPACE) {
         $found = strlen($tokens[$stackPtr + 1]['content']);
         $error = 'Expected 0 spaces after double colon; %s found';
         $data = array($found);
         $phpcsFile->addError($error, $className, 'SpaceAfter', $data);
     }
 }
开发者ID:altesien,项目名称:FinalProject,代码行数:48,代码来源:SelfMemberReferenceSniff.php

示例14: 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
  * @see PHP_CodeSniffer_Sniff::process()
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $token = $tokens[$stackPtr]['content'];
     // Only accept class member functions
     if (false === $phpcsFile->hasCondition($stackPtr, T_CLASS)) {
         return;
     }
     $nextTokenIndex = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true);
     $methodName = $tokens[$nextTokenIndex]['content'];
     $methodProperties = $phpcsFile->getMethodProperties($stackPtr);
     if (true === $methodProperties['is_abstract']) {
         // Warning for abstract static declared functions
         if (true === $methodProperties['is_static']) {
             $warning = sprintf('Abstract function "%s" should not be declared static!', $methodName);
             $phpcsFile->addWarning($warning, $stackPtr);
         }
         // Error for static abstract declared functions
         if ('private' === $methodProperties['scope']) {
             $error = sprintf('Abstract function "%s" can not be declared private!', $methodName);
             $phpcsFile->addError($error, $stackPtr);
         }
     }
 }
开发者ID:foobugs-standards,项目名称:php52to53,代码行数:34,代码来源:AbstractMethodsSniff.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();
     $constName = $tokens[$stackPtr]['content'];
     // If this token is in a heredoc, ignore it.
     if ($phpcsFile->hasCondition($stackPtr, T_START_HEREDOC) === true) {
         return;
     }
     // Special case for PHPUnit.
     if ($constName === 'PHPUnit_MAIN_METHOD') {
         return;
     }
     // If the next non-whitespace token after this token
     // is not an opening parenthesis then it is not a function call.
     $openBracket = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
     if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
         $functionKeyword = $phpcsFile->findPrevious(array(T_WHITESPACE, T_COMMA, T_COMMENT, T_STRING, T_NS_SEPARATOR), $stackPtr - 1, null, true);
         $declarations = array(T_FUNCTION, T_CLASS, T_INTERFACE, T_TRAIT, T_IMPLEMENTS, T_EXTENDS, T_INSTANCEOF, T_NEW, T_NAMESPACE, T_USE, T_AS, T_GOTO, T_INSTEADOF);
         if (in_array($tokens[$functionKeyword]['code'], $declarations) === true) {
             // This is just a declaration; no constants here.
             return;
         }
         if ($tokens[$functionKeyword]['code'] === T_CONST) {
             // This is a class constant.
             if (strtoupper($constName) !== $constName) {
                 $error = 'Class constants must be uppercase; expected %s but found %s';
                 $data = array(strtoupper($constName), $constName);
                 $phpcsFile->addError($error, $stackPtr, 'ClassConstantNotUpperCase', $data);
             }
             return;
         }
         // Is this a class name?
         $nextPtr = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
         if ($tokens[$nextPtr]['code'] === T_DOUBLE_COLON) {
             return;
         }
         // Is this a namespace name?
         if ($tokens[$nextPtr]['code'] === T_NS_SEPARATOR) {
             return;
         }
         // Is this an insteadof name?
         if ($tokens[$nextPtr]['code'] === T_INSTEADOF) {
             return;
         }
         // Is this a type hint?
         if ($tokens[$nextPtr]['code'] === T_VARIABLE || $phpcsFile->isReference($nextPtr) === true) {
             return;
         }
         // Is this a member var name?
         $prevPtr = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true);
         if ($tokens[$prevPtr]['code'] === T_OBJECT_OPERATOR) {
             return;
         }
         // Is this a variable name, in the form ${varname} ?
         if ($tokens[$prevPtr]['code'] === T_OPEN_CURLY_BRACKET) {
             $nextPtr = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
             if ($tokens[$nextPtr]['code'] === T_CLOSE_CURLY_BRACKET) {
                 return;
             }
         }
         // Is this a namespace name?
         if ($tokens[$prevPtr]['code'] === T_NS_SEPARATOR) {
             return;
         }
         // Is this an instance of declare()
         $prevPtrDeclare = $phpcsFile->findPrevious(array(T_WHITESPACE, T_OPEN_PARENTHESIS), $stackPtr - 1, null, true);
         if ($tokens[$prevPtrDeclare]['code'] === T_DECLARE) {
             return;
         }
         // Is this a goto label target?
         if ($tokens[$nextPtr]['code'] === T_COLON) {
             if (in_array($tokens[$prevPtr]['code'], array(T_SEMICOLON, T_OPEN_CURLY_BRACKET, T_COLON), true)) {
                 return;
             }
         }
         // This is a real constant.
         if (strtoupper($constName) !== $constName) {
             $error = 'Constants must be uppercase; expected %s but found %s';
             $data = array(strtoupper($constName), $constName);
             $phpcsFile->addError($error, $stackPtr, 'ConstantNotUpperCase', $data);
         }
     } else {
         if (strtolower($constName) === 'define' || strtolower($constName) === 'constant') {
             /*
                 This may be a "define" or "constant" function call.
             */
             // Make sure this is not a method call.
             $prev = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true);
             if ($tokens[$prev]['code'] === T_OBJECT_OPERATOR || $tokens[$prev]['code'] === T_DOUBLE_COLON) {
                 return;
             }
//.........这里部分代码省略.........
开发者ID:kameshwariv,项目名称:testexample,代码行数:101,代码来源:UpperCaseConstantNameSniff.php


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