當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。