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


PHP PHP_CodeSniffer_File::getdeclarationname方法代码示例

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


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

示例1: processreturn

 /**
  * Process the return comment of this function comment.
  *
  * @param int $commentstart The position in the stack where the comment started.
  * @param int $commentend   The position in the stack where the comment ended.
  *
  * @return void
  */
 protected function processreturn($commentstart, $commentend)
 {
     // Skip constructor and destructor.
     $classname = '';
     if ($this->_classtoken !== null) {
         $classname = $this->currentfile->getdeclarationname($this->_classtoken);
         $classname = strtolower(ltrim($classname, '_'));
     }
     $methodname = strtolower(ltrim($this->_methodname, '_'));
     $isspecialmethod = $this->_methodname === '__construct' || $this->_methodname === '__destruct';
     if ($isspecialmethod === false && $methodname !== $classname) {
         // Report missing return tag.
         if ($this->commentparser->getreturn() === null) {
             $error = 'Missing @return tag in function comment';
             $this->currentfile->adderror($error, $commentend);
         } else {
             if (trim($this->commentparser->getreturn()->getrawcontent()) === '') {
                 $error = '@return tag is empty in function comment';
                 $errorpos = $commentstart + $this->commentparser->getreturn()->getline();
                 $this->currentfile->adderror($error, $errorpos);
             }
         }
     }
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:32,代码来源:FunctionCommentSniff.php

示例2: 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];
     // Skip function without body.
     if (isset($token['scope_opener']) === false) {
         return;
     }
     // Get function name.
     $methodname = $phpcsfile->getdeclarationname($stackptr);
     // Get all parameters from method signature.
     $signature = array();
     foreach ($phpcsfile->getmethodparameters($stackptr) as $param) {
         $signature[] = $param['name'];
     }
     $next = ++$token['scope_opener'];
     $end = --$token['scope_closer'];
     for (; $next <= $end; ++$next) {
         $code = $tokens[$next]['code'];
         if (in_array($code, PHP_CodeSniffer_tokens::$emptyTokens) === true) {
             continue;
         } else {
             if ($code === T_RETURN) {
                 continue;
             }
         }
         break;
     }
     // Any token except 'parent' indicates correct code.
     if ($tokens[$next]['code'] !== T_PARENT) {
         return;
     }
     // Find next non empty token index, should be double colon.
     $next = $phpcsfile->findnext(PHP_CodeSniffer_tokens::$emptyTokens, $next + 1, null, true);
     // Skip for invalid code.
     if ($next === false || $tokens[$next]['code'] !== T_DOUBLE_COLON) {
         return;
     }
     // Find next non empty token index, should be the function name.
     $next = $phpcsfile->findnext(PHP_CodeSniffer_tokens::$emptyTokens, $next + 1, null, true);
     // Skip for invalid code or other method.
     if ($next === false || $tokens[$next]['content'] !== $methodname) {
         return;
     }
     // Find next non empty token index, should be the open parenthesis.
     $next = $phpcsfile->findnext(PHP_CodeSniffer_tokens::$emptyTokens, $next + 1, null, true);
     // Skip for invalid code.
     if ($next === false || $tokens[$next]['code'] !== T_OPEN_PARENTHESIS) {
         return;
     }
     $validparametertypes = array(T_VARIABLE, T_LNUMBER, T_CONSTANT_ENCAPSED_STRING);
     $parameters = array('');
     $parenthesiscount = 1;
     $count = count($tokens);
     for (++$next; $next < $count; ++$next) {
         $code = $tokens[$next]['code'];
         if ($code === T_OPEN_PARENTHESIS) {
             ++$parenthesiscount;
         } else {
             if ($code === T_CLOSE_PARENTHESIS) {
                 --$parenthesiscount;
             } else {
                 if ($parenthesiscount === 1 && $code === T_COMMA) {
                     $parameters[] = '';
                 } else {
                     if (in_array($code, PHP_CodeSniffer_tokens::$emptyTokens) === false) {
                         $parameters[count($parameters) - 1] .= $tokens[$next]['content'];
                     }
                 }
             }
         }
         if ($parenthesiscount === 0) {
             break;
         }
     }
     $next = $phpcsfile->findnext(PHP_CodeSniffer_tokens::$emptyTokens, $next + 1, null, true);
     if ($next === false || $tokens[$next]['code'] !== T_SEMICOLON) {
         return;
     }
     // Check rest of the scope.
     for (++$next; $next <= $end; ++$next) {
         $code = $tokens[$next]['code'];
         // Skip for any other content.
         if (in_array($code, PHP_CodeSniffer_tokens::$emptyTokens) === false) {
             return;
         }
     }
     $parameters = array_map('trim', $parameters);
     $parameters = array_filter($parameters);
     if (count($parameters) === count($signature) && $parameters === $signature) {
         $phpcsfile->addwarning('Useless method overriding detected', $stackptr);
//.........这里部分代码省略.........
开发者ID:vuchannguyen,项目名称:web,代码行数:101,代码来源:UselessOverridingMethodSniff.php

示例3: processtokenoutsidescope

 /**
  * Processes the tokens outside the scope.
  *
  * @param PHP_CodeSniffer_File $phpcsfile The file being processed.
  * @param int                  $stackptr  The position where this token was
  *                                        found.
  *
  * @return void
  */
 protected function processtokenoutsidescope(PHP_CodeSniffer_File $phpcsfile, $stackptr)
 {
     $functionname = $phpcsfile->getdeclarationname($stackptr);
     // Is this a magic function. IE. is prefixed with "__".
     if (preg_match('|^__|', $functionname) !== 0) {
         $magicpart = substr($functionname, 2);
         if (in_array($magicpart, $this->_magicfunctions) === false) {
             $error = "Function name \"{$functionname}\" is invalid; " . 'only PHP magic methods should be prefixed with a double underscore';
             $phpcsfile->adderror($error, $stackptr);
         }
         return;
     }
     // Only lower-case accepted
     if (preg_match('/[A-Z]+/', $functionname)) {
         $error = "function name \"{$functionname}\" must be lower-case letters only";
         $phpcsfile->adderror($error, $stackptr);
         return;
     }
     // Only letters accepted
     if (preg_match('/[0-9]+/', $functionname)) {
         $error = "function name \"{$functionname}\" must only contain letters";
         $phpcsfile->adderror($error, $stackptr);
         return;
     }
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:34,代码来源:ValidFunctionNameSniff.php


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