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


PHP PHP_CodeSniffer_File::getMethodProperties方法代码示例

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


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

示例1: processTokenWithinScope

 /**
  * Processes the tokens within the scope.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file being processed.
  * @param int                  $stackPtr  The position where this token was
  *                                        found.
  * @param int                  $currScope The position of the current scope.
  *
  * @return void
  */
 protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
 {
     $methodName = $phpcsFile->getDeclarationName($stackPtr);
     if ($methodName === null) {
         // Ignore closures.
         return;
     }
     $className = $phpcsFile->getDeclarationName($currScope);
     $errorData = array($className . '::' . $methodName);
     // Is this a magic method. IE. is prefixed with "__".
     if (preg_match('|^__|', $methodName) !== 0) {
         $magicPart = substr($methodName, 2);
         if (in_array($magicPart, $this->magicMethods) === false) {
             $error = 'Method name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore';
             $phpcsFile->addError($error, $stackPtr, 'MethodDoubleUnderscore', $errorData);
         }
         return;
     }
     $methodProps = $phpcsFile->getMethodProperties($stackPtr);
     $scope = $methodProps['scope'];
     $scopeSpecified = $methodProps['scope_specified'];
     // Methods should not contain underscores.
     if (strpos($methodName, '_') !== false) {
         if ($scopeSpecified === true) {
             $error = '%s method name "%s" is not in lowerCamel format, it must not contain underscores';
             $data = array(ucfirst($scope), $errorData[0]);
             $phpcsFile->addError($error, $stackPtr, 'ScopeNotLowerCamel', $data);
         } else {
             $error = 'Method name "%s" is not in lowerCamel format, it must not contain underscores';
             $phpcsFile->addError($error, $stackPtr, 'NotLowerCamel', $errorData);
         }
     }
 }
开发者ID:ecs-hk,项目名称:Checkbook,代码行数:43,代码来源:ValidFunctionNameSniff.php

示例2: processTokenWithinScope

 /**
  * Processes this test, when one of its tokens is encountered.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The current file being scanned.
  * @param integer                  $stackPtr  The position of the current token in the
  *                                        stack passed in $tokens.
  * @param integer                  $currScope A pointer to the start of the scope.
  *
  * @return void
  */
 public function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
 {
     $tokens = $phpcsFile->getTokens();
     $function = $tokens[$stackPtr + 2];
     if ($function['code'] !== T_STRING) {
         return;
     }
     $functionName = $function['content'];
     $classOpener = $tokens[$currScope]['scope_condition'];
     $className = $tokens[$classOpener + 2]['content'];
     $methodProps = $phpcsFile->getMethodProperties($stackPtr);
     if ($methodProps['is_static'] === true) {
         if (isset($tokens[$stackPtr]['scope_closer']) === false) {
             // There is no scope opener or closer, so the function
             // must be abstract.
             return;
         }
         $thisUsage = $stackPtr;
         while (($thisUsage = $phpcsFile->findNext(array(T_VARIABLE), $thisUsage + 1, $tokens[$stackPtr]['scope_closer'], false, '$this')) !== false) {
             if ($thisUsage === false) {
                 return;
             }
             $error = 'Usage of "$this" in static methods will cause runtime errors';
             $phpcsFile->addError($error, $thisUsage, 'Found');
         }
         //while
     }
 }
开发者ID:greencape,项目名称:coding-standards,代码行数:38,代码来源:StaticThisUsageSniff.php

示例3: processTokenWithinScope

 /**
  * Processes the tokens within the scope.
  *
  * @param PHP_CodeSniffer_File $phpcsfile The file being processed.
  * @param int                  $stackptr  The position where this token was
  *                                        found.
  * @param int                  $currscope The position of the current scope.
  *
  * @return void
  */
 protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsfile, $stackptr, $currscope)
 {
     $classname = $phpcsfile->getDeclarationName($currscope);
     $methodname = $phpcsfile->getDeclarationName($stackptr);
     // Is this a magic method. IE. is prefixed with "__".
     if (preg_match('|^__|', $methodname) !== 0) {
         $magicpart = substr($methodname, 2);
         if (!in_array($magicpart, $this->magicmethods)) {
             $error = "method name \"{$classname}::{$methodname}\" is invalid; " . 'only PHP magic methods should be prefixed with a double underscore';
             $phpcsfile->addError($error, $stackptr);
         }
         return;
     }
     $methodprops = $phpcsfile->getMethodProperties($stackptr);
     $scope = $methodprops['scope'];
     $scopespecified = $methodprops['scope_specified'];
     // Only lower-case accepted
     if (preg_match('/[A-Z]+/', $methodname) && !in_array($methodname, $this->permittedmethods)) {
         if ($scopespecified === true) {
             $error = ucfirst($scope) . ' method name "' . $classname . '::' . $methodname . '" must be in lower-case letters only';
         } else {
             $error = 'method name "' . $classname . '::' . $methodname . '" must be in lower-case letters only';
         }
         $phpcsfile->adderror($error, $stackptr);
         return;
     }
 }
开发者ID:moodlerooms,项目名称:moodle-coding-standard,代码行数:37,代码来源:ValidFunctionNameSniff.php

示例4: 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

示例5: processTokenWithinScope

 protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
 {
     $className = $phpcsFile->getDeclarationName($currScope);
     $methodName = $phpcsFile->getDeclarationName($stackPtr);
     // Only magic methods should be prefixed with "__"
     if (preg_match('|^__|', $methodName) !== 0) {
         $magicPart = substr($methodName, 2);
         if (in_array($magicPart, $this->magicMethods) === false) {
             $error = sprintf("Method name \"%s::%s\" is invalid; only PHP magic methods should be prefixed with a double underscore", $className, $methodName);
             $phpcsFile->addError($error, $stackPtr);
         }
         return;
     }
     // There should be given a valid scope
     $methodProperties = $phpcsFile->getMethodProperties($stackPtr);
     if ($methodProperties['scope_specified'] !== true) {
         $error = sprintf("No scope declaration for method \"%s::%s\" found", $className, $methodName);
         $phpcsFile->addWarning($error, $stackPtr);
         return;
     }
     // Method names should be camel-cased and not underscored
     if (PHP_CodeSniffer::isCamelCaps($methodName, false, true, false) === false) {
         $error = sprintf("Method name \"%s::%s\" is not in camel caps format", $className, $methodName);
         $phpcsFile->addError($error, $stackPtr);
         return;
     }
 }
开发者ID:b00giZm,项目名称:phpcs-missing-standards,代码行数:27,代码来源:ValidFunctionNameSniff.php

示例6: processTokenWithinScope

 /**
  * Processes the tokens within the scope.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file being processed.
  * @param int                  $stackPtr  The position where this token was
  *                                        found.
  * @param int                  $currScope The position of the current scope.
  *
  * @return void
  */
 protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
 {
     $methodName = $phpcsFile->getDeclarationName($stackPtr);
     if ($methodName === null) {
         // Ignore closures.
         return;
     }
     $className = $phpcsFile->getDeclarationName($currScope);
     $errorData = array($className . '::' . $methodName);
     // Is this a magic method. i.e., is prefixed with "__" ?
     if (preg_match('|^__|', $methodName) !== 0) {
         $magicPart = strtolower(substr($methodName, 2));
         if (isset($this->magicMethods[$magicPart]) === false && isset($this->methodsDoubleUnderscore[$magicPart]) === false) {
             $error = 'Method name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore';
             $phpcsFile->addError($error, $stackPtr, 'MethodDoubleUnderscore', $errorData);
         }
         return;
     }
     $methodProps = $phpcsFile->getMethodProperties($stackPtr);
     if (PHP_CodeSniffer::isCamelCaps($methodName, false, true, $this->strict) === false) {
         if ($methodProps['scope_specified'] === true) {
             $error = '%s method name "%s" is not in lowerCamel format';
             $data = array(ucfirst($methodProps['scope']), $errorData[0]);
             $phpcsFile->addError($error, $stackPtr, 'ScopeNotCamelCaps', $data);
         } else {
             $error = 'Method name "%s" is not in lowerCamel format';
             $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData);
         }
         $phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'no');
         return;
     } else {
         $phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'yes');
     }
 }
开发者ID:atif-shaikh,项目名称:DCX-Profile,代码行数:44,代码来源:ValidFunctionNameSniff.php

示例7: processTokenWithinScope

 /**
  * Processes the tokens within the scope.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file being processed.
  * @param int                  $stackPtr  The position where this token was
  *                                        found.
  * @param int                  $currScope The position of the current scope.
  *
  * @return void
  */
 protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
 {
     $className = $phpcsFile->getDeclarationName($currScope);
     $methodName = $phpcsFile->getDeclarationName($stackPtr);
     // Is this a magic method. IE. is prefixed with "__".
     if (preg_match('|^__|', $methodName) !== 0) {
         $magicPart = substr($methodName, 2);
         if (in_array($magicPart, $this->_magicMethods) === false) {
             $error = "Method name \"{$className}::{$methodName}\" is invalid; only PHP magic methods should be prefixed with a double underscore";
             $phpcsFile->addError($error, $stackPtr);
         }
         return;
     }
     // PHP4 constructors are allowed to break our rules.
     if ($methodName === $className) {
         return;
     }
     // PHP4 destructors are allowed to break our rules.
     if ($methodName === '_' . $className) {
         return;
     }
     $methodProps = $phpcsFile->getMethodProperties($stackPtr);
     $isPublic = $methodProps['scope'] === 'public' ? true : false;
     $scope = $methodProps['scope'];
     $scopeSpecified = $methodProps['scope_specified'];
     // If it's a private method, it must have an underscore on the front.
     if ($isPublic === false && $methodName[0] !== '_') {
         $error = ucfirst($scope) . " method name \"{$className}::{$methodName}\" must be prefixed with an underscore";
         $phpcsFile->addError($error, $stackPtr);
         return;
     }
     // If it's not a private method, it must not have an underscore on the front.
     if ($isPublic === true && $scopeSpecified === true && $methodName[0] === '_') {
         $error = "Public method name \"{$className}::{$methodName}\" must not be prefixed with an underscore";
         $phpcsFile->addError($error, $stackPtr);
         return;
     }
     // If the scope was specified on the method, then the method must be
     // camel caps and an underscore should be checked for. If it wasn't
     // specified, treat it like a public method and remove the underscore
     // prefix if there is one because we cant determine if it is private or
     // public.
     $testMethodName = $methodName;
     if ($scopeSpecified === false && $methodName[0] === '_') {
         $testMethodName = substr($methodName, 1);
     }
     if (PHP_CodeSniffer::isCamelCaps($testMethodName, false, $isPublic, false) === false) {
         if ($scopeSpecified === true) {
             $error = ucfirst($scope) . " method name \"{$className}::{$methodName}\" is not in camel caps format";
         } else {
             $error = "Method name \"{$className}::{$methodName}\" is not in camel caps format";
         }
         $phpcsFile->addError($error, $stackPtr);
         return;
     }
 }
开发者ID:hellogerard,项目名称:pox-framework,代码行数:66,代码来源:ValidFunctionNameSniff.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 ($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

示例9: processTokenWithinScope

 /**
  * Processes the tokens within the scope.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file being processed.
  * @param integer $stackPtr The position where this token was found.
  * @param integer $currScope The position of the current scope.
  * @return void
  */
 protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
 {
     $methodName = $phpcsFile->getDeclarationName($stackPtr);
     if ($methodName === null) {
         // Ignore closures.
         return;
     }
     $className = $phpcsFile->getDeclarationName($currScope);
     $errorData = array($className . '::' . $methodName);
     // PHP4 constructors are allowed to break our rules.
     if ($methodName === $className) {
         return;
     }
     // PHP4 destructors are allowed to break our rules.
     if ($methodName === '_' . $className) {
         return;
     }
     // Ignore magic methods
     if (preg_match('/^__(' . implode('|', $this->_magicMethods) . ')$/', $methodName)) {
         return;
     }
     $methodProps = $phpcsFile->getMethodProperties($stackPtr);
     if ($methodProps['scope_specified'] === false) {
         // Let another sniffer take care of that
         return;
     }
     $isPublic = $methodProps['scope'] === 'public';
     $isProtected = $methodProps['scope'] === 'protected';
     $isPrivate = $methodProps['scope'] === 'private';
     $scope = $methodProps['scope'];
     if ($isPublic === true) {
         if ($methodName[0] === '_') {
             $error = 'Public method name "%s" must not be prefixed with underscore';
             $phpcsFile->addError($error, $stackPtr, 'PublicWithUnderscore', $errorData);
             return;
         }
         // Underscored public methods in controller are allowed to break our rules.
         if (substr($className, -10) === 'Controller') {
             return;
         }
         // Underscored public methods in shells are allowed to break our rules.
         if (substr($className, -5) === 'Shell') {
             return;
         }
         // Underscored public methods in tasks are allowed to break our rules.
         if (substr($className, -4) === 'Task') {
             return;
         }
     } elseif ($isPrivate === true) {
         $filename = $phpcsFile->getFilename();
         $warning = 'Private method name "%s" in CakePHP core is discouraged';
         $phpcsFile->addWarning($warning, $stackPtr, 'PrivateMethodInCore', $errorData);
     }
 }
开发者ID:tuffz,项目名称:cakephp_codesniffer,代码行数:62,代码来源:ValidFunctionNameSniff.php

示例10: 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)
 {
     $methodName = $phpcsFile->getDeclarationName($stackPtr);
     $methodProps = $phpcsFile->getMethodProperties($stackPtr);
     if ($methodProps['is_static']) {
         if (!PHP_CodeSniffer_Standards_Silverstripe_SilverstripeCodingStandard::isLowerCaseWithUnderScore($methodName)) {
             $error = "Function name \"{$methodName}\" is invalid Static methods should be in lowercase_with_underscores() format.";
             $phpcsFile->addError($error, $stackPtr);
         }
     } else {
     }
 }
开发者ID:natmchugh,项目名称:Silverstripe-Code-Sniffs,代码行数:21,代码来源:ValidFunctionNameSniff.php

示例11: isTestClassMethod

 /**
  * Check if a method is a PHPUnit test class method.
  * @param  int $stackPtr
  * @return bool
  */
 public function isTestClassMethod($stackPtr)
 {
     if (!array_key_exists($stackPtr, $this->testClassMethods)) {
         $this->testClassMethods[$stackPtr] = false;
         if ($this->isTestClass($stackPtr)) {
             $props = $this->phpcsFile->getMethodProperties($stackPtr);
             if ('public' == $props['scope'] && !$props['is_abstract'] && !$props['is_closure'] && stripos($this->phpcsFile->getDeclarationName($stackPtr), 'test') === 0) {
                 $this->testClassMethods[$stackPtr] = true;
             }
         }
     }
     return $this->testClassMethods[$stackPtr];
 }
开发者ID:gamegos,项目名称:php-code-sniffer,代码行数:18,代码来源:ClassHelper.php

示例12: process

 /**
  * {@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);
 }
开发者ID:move-elevator,项目名称:symfony-coding-standard,代码行数:17,代码来源:FunctionCommentSniff.php

示例13: processTokenWithinScope

 /**
  * Override parent function to allow custom code validation
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file being processed.
  * @param int                  $stackPtr  The position where this token was
  *                                        found.
  * @param int                  $currScope The position of the current scope.
  *
  * @return void
  */
 protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
 {
     $methodName = $phpcsFile->getDeclarationName($stackPtr);
     if ($methodName === null) {
         // Ignore closures.
         return;
     }
     $className = $phpcsFile->getDeclarationName($currScope);
     // Is this a magic method. IE. is prefixed with "__".
     if (preg_match('|^__|', $methodName) !== 0) {
         $magicPart = substr($methodName, 2);
         if (in_array($magicPart, $this->magicMethods) === false) {
             $error = "Method name \"{$className}::{$methodName}\" is invalid; only PHP magic methods should be prefixed with a double underscore";
             $phpcsFile->addError($error, $stackPtr);
         }
         return;
     }
     // PHP4 constructors are allowed to break our rules.
     if ($methodName === $className) {
         return;
     }
     // PHP4 destructors are allowed to break our rules.
     if ($methodName === '_' . $className) {
         return;
     }
     $methodProps = $phpcsFile->getMethodProperties($stackPtr);
     $isPublic = $methodProps['scope'] === 'private' ? false : true;
     $scope = $methodProps['scope'];
     $scopeSpecified = $methodProps['scope_specified'];
     // If it's a private method, it must have an underscore on the front.
     if ($isPublic === false && $methodName[0] !== '_') {
         $error = "Private method name \"{$className}::{$methodName}\" must be prefixed with an underscore";
         $phpcsFile->addError($error, $stackPtr);
         return;
     }
     // We want to allow private and protected methods to start with an underscore
     $testMethodName = $methodName;
     if (($scopeSpecified === false || $scope == 'protected') && $methodName[0] === '_') {
         $testMethodName = substr($methodName, 1);
     }
     if (PHP_CodeSniffer::isCamelCaps($testMethodName, false, $isPublic, false) === false) {
         if ($scopeSpecified === true) {
             $error = ucfirst($scope) . " method name \"{$className}::{$methodName}\" is not in camel caps format";
         } else {
             $error = "Method name \"{$className}::{$methodName}\" is not in camel caps format";
         }
         $phpcsFile->addError($error, $stackPtr);
         return;
     }
 }
开发者ID:Aeryris,项目名称:grid,代码行数:60,代码来源:ValidFunctionNameSniff.php

示例14: processTokenWithinScope

 /**
  * Processes the tokens within the scope.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file being processed.
  * @param int                  $stackPtr  The position where this token was
  *                                        found.
  * @param int                  $currScope The position of the current scope.
  *
  * @return void
  */
 protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
 {
     $methodName = $phpcsFile->getDeclarationName($stackPtr);
     if ($methodName === null) {
         // Ignore closures.
         return;
     }
     $className = $phpcsFile->getDeclarationName($currScope);
     $errorData = array($className . '::' . $methodName);
     // Is this a magic method. IE. is prefixed with "__".
     if (preg_match('|^__|', $methodName) !== 0) {
         $magicPart = strtolower(substr($methodName, 2));
         if (in_array($magicPart, $this->magicMethods) === false) {
             $error = 'Method name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore';
             $phpcsFile->addError($error, $stackPtr, 'MethodDoubleUnderscore', $errorData);
         }
         return;
     }
     $methodProps = $phpcsFile->getMethodProperties($stackPtr);
     $scope = $methodProps['scope'];
     $scopeSpecified = $methodProps['scope_specified'];
     // If it's not a private method, it must not have an underscore on the front.
     if ($scopeSpecified === true && $methodName[0] === '_') {
         $error = '%s method name "%s" must not be prefixed with an underscore';
         $data = array(ucfirst($scope), $errorData[0]);
         $phpcsFile->addError($error, $stackPtr, 'MethodUnderscore', $data);
         return;
     }
     // If the scope was specified on the method, then the method must be
     // camel caps and an underscore should be checked for. If it wasn't
     // specified, treat it like a public method and remove the underscore
     // prefix if there is one because we cant determine if it is private or
     // public.
     $testMethodName = $methodName;
     if ($scopeSpecified === false && $methodName[0] === '_') {
         $testMethodName = substr($methodName, 1);
     }
     if (PHP_CodeSniffer::isCamelCaps($testMethodName, false, true, false) === false) {
         if ($scopeSpecified === true) {
             $error = '%s method name "%s" is not in camel caps format';
             $data = array(ucfirst($scope), $errorData[0]);
             $phpcsFile->addError($error, $stackPtr, 'ScopeNotCamelCaps', $data);
         } else {
             $error = 'Method name "%s" is not in camel caps format';
             $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData);
         }
         return;
     }
 }
开发者ID:zumba,项目名称:zumba-coding-standards,代码行数:59,代码来源:ValidFunctionNameSniff.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)
 {
     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);
 }
开发者ID:biggtfish,项目名称:cms,代码行数:24,代码来源:FunctionCommentSniff.php


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