当前位置: 首页>>代码示例>>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;未经允许,请勿转载。