当前位置: 首页>>代码示例>>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方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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)
 {
     $find = array(T_COMMENT, T_DOC_COMMENT, T_CLASS, T_FUNCTION, T_OPEN_TAG);
     $commentend = $phpcsfile->findprevious($find, $stackptr - 1);
     if ($commentend === false) {
         return;
     }
     $this->currentfile = $phpcsfile;
     $tokens = $phpcsfile->gettokens();
     // If the token that we found was a class or a function, then this
     // function has no doc comment.
     $code = $tokens[$commentend]['code'];
     if ($code === T_COMMENT) {
         $error = 'You must use "/**" style comments for a function comment';
         $phpcsfile->adderror($error, $stackptr);
         return;
     } else {
         if ($code !== T_DOC_COMMENT) {
             $phpcsfile->adderror('Missing function doc comment', $stackptr);
             return;
         }
     }
     // If there is any code between the function keyword and the doc block
     // then the doc block is not for us.
     $ignore = PHP_CodeSniffer_tokens::$scopeModifiers;
     $ignore[] = T_STATIC;
     $ignore[] = T_WHITESPACE;
     $ignore[] = T_ABSTRACT;
     $ignore[] = T_FINAL;
     $prevtoken = $phpcsfile->findprevious($ignore, $stackptr - 1, null, true);
     if ($prevtoken !== $commentend) {
         $phpcsfile->adderror('Missing function doc comment', $stackptr);
         return;
     }
     $this->_functiontoken = $stackptr;
     foreach ($tokens[$stackptr]['conditions'] as $condptr => $condition) {
         if ($condition === T_CLASS || $condition === T_INTERFACE) {
             $this->_classtoken = $condptr;
             break;
         }
     }
     // If the first T_OPEN_TAG is right before the comment, it is probably
     // a file comment.
     $commentstart = $phpcsfile->findprevious(T_DOC_COMMENT, $commentend - 1, null, true) + 1;
     $prevtoken = $phpcsfile->findprevious(T_WHITESPACE, $commentstart - 1, null, true);
     if ($tokens[$prevtoken]['code'] === T_OPEN_TAG) {
         // Is this the first open tag?
         if ($stackptr === 0 || $phpcsfile->findprevious(T_OPEN_TAG, $prevtoken - 1) === false) {
             $phpcsfile->adderror('Missing function doc comment', $stackptr);
             return;
         }
     }
     $comment = $phpcsfile->gettokensAsString($commentstart, $commentend - $commentstart + 1);
     $this->_methodname = $phpcsfile->getDeclarationname($stackptr);
     try {
         $this->commentparser = new PHP_CodeSniffer_CommentParser_FunctionCommentParser($comment, $phpcsfile);
         $this->commentparser->parse();
     } catch (PHP_CodeSniffer_CommentParser_ParserException $e) {
         $line = $e->getlinewithinComment() + $commentstart;
         $phpcsfile->adderror($e->getMessage(), $line);
         return;
     }
     $comment = $this->commentparser->getComment();
     if (is_null($comment) === true) {
         $error = 'Function doc comment is empty';
         $phpcsfile->adderror($error, $commentstart);
         return;
     }
     $this->processparams($commentstart);
     $this->processreturn($commentstart, $commentend);
     $this->processthrows($commentstart);
     // No extra newline before short description.
     $short = $comment->getShortComment();
     $newlinecount = 0;
     $newlinespan = strspn($short, $phpcsfile->eolChar);
     if ($short !== '' && $newlinespan > 0) {
         $line = $newlinespan > 1 ? 'newlines' : 'newline';
         $error = "Extra {$line} found before function comment short description";
         $phpcsfile->adderror($error, $commentstart + 1);
     }
     $newlinecount = substr_count($short, $phpcsfile->eolChar) + 1;
     // Exactly one blank line between short and long description.
     $long = $comment->getlongcomment();
     if (empty($long) === false) {
         $between = $comment->getWhiteSpacebetween();
         $newlinebetween = substr_count($between, $phpcsfile->eolChar);
         if ($newlinebetween !== 2) {
             $error = 'There must be exactly one blank line between descriptions in function comment';
             $phpcsfile->adderror($error, $commentstart + $newlinecount + 1);
         }
         $newlinecount += $newlinebetween;
//.........这里部分代码省略.........
开发者ID:vuchannguyen,项目名称:web,代码行数:101,代码来源:FunctionCommentSniff.php


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