當前位置: 首頁>>代碼示例>>PHP>>正文


PHP File::getFileName方法代碼示例

本文整理匯總了PHP中PHP_CodeSniffer\Files\File::getFileName方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::getFileName方法的具體用法?PHP File::getFileName怎麽用?PHP File::getFileName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PHP_CodeSniffer\Files\File的用法示例。


在下文中一共展示了File::getFileName方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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 int
  */
 public function process(File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $fileName = $phpcsFile->getFileName();
     $extension = substr($fileName, strrpos($fileName, '.'));
     $nextClass = $phpcsFile->findNext(array(T_CLASS, T_INTERFACE, T_TRAIT), $stackPtr);
     if ($nextClass !== false) {
         $phpcsFile->recordMetric($stackPtr, 'File extension for class files', $extension);
         if ($extension === '.php') {
             $error = '%s found in ".php" file; use ".inc" extension instead';
             $data = array(ucfirst($tokens[$nextClass]['content']));
             $phpcsFile->addError($error, $stackPtr, 'ClassFound', $data);
         }
     } else {
         $phpcsFile->recordMetric($stackPtr, 'File extension for non-class files', $extension);
         if ($extension === '.inc') {
             $error = 'No interface or class found in ".inc" file; use ".php" extension instead';
             $phpcsFile->addError($error, $stackPtr, 'NoClass');
         }
     }
     // Ignore the rest of the file.
     return $phpcsFile->numTokens + 1;
 }
開發者ID:thekabal,項目名稱:tki,代碼行數:32,代碼來源:FileExtensionSniff.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(File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     // Make sure this is the first PHP open tag so we don't process the
     // same file twice.
     $prevOpenTag = $phpcsFile->findPrevious(T_OPEN_TAG, $stackPtr - 1);
     if ($prevOpenTag !== false) {
         return;
     }
     $path = $phpcsFile->getFileName();
     $properties = $this->getProperties($path);
     if ($properties === null) {
         // Not under version control.
         return;
     }
     $allProperties = $properties + $this->properties;
     foreach ($allProperties as $key => $value) {
         if (isset($properties[$key]) === true && isset($this->properties[$key]) === false) {
             $error = 'Unexpected Subversion property "%s" = "%s"';
             $data = array($key, $properties[$key]);
             $phpcsFile->addError($error, $stackPtr, 'Unexpected', $data);
             continue;
         }
         if (isset($properties[$key]) === false && isset($this->properties[$key]) === true) {
             $error = 'Missing Subversion property "%s" = "%s"';
             $data = array($key, $this->properties[$key]);
             $phpcsFile->addError($error, $stackPtr, 'Missing', $data);
             continue;
         }
         if ($properties[$key] !== null && $properties[$key] !== $this->properties[$key]) {
             $error = 'Subversion property "%s" = "%s" does not match "%s"';
             $data = array($key, $properties[$key], $this->properties[$key]);
             $phpcsFile->addError($error, $stackPtr, 'NoMatch', $data);
         }
     }
     //end foreach
 }
開發者ID:thekabal,項目名稱:tki,代碼行數:46,代碼來源:SubversionPropertiesSniff.php


注:本文中的PHP_CodeSniffer\Files\File::getFileName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。