本文整理汇总了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;
}
示例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
}