本文整理汇总了PHP中PHP_CodeSniffer_File::getClassProperties方法的典型用法代码示例。如果您正苦于以下问题:PHP PHP_CodeSniffer_File::getClassProperties方法的具体用法?PHP PHP_CodeSniffer_File::getClassProperties怎么用?PHP PHP_CodeSniffer_File::getClassProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHP_CodeSniffer_File
的用法示例。
在下文中一共展示了PHP_CodeSniffer_File::getClassProperties方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The current file being processed.
* @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)
{
$tokens = $phpcsFile->getTokens();
$className = $phpcsFile->findNext(T_STRING, $stackPtr);
$name = trim($tokens[$className]['content']);
$errorData = array(ucfirst($tokens[$stackPtr]['content']));
$classProperties = $phpcsFile->getClassProperties($stackPtr);
$startsWithAbstract = substr($name, 0, 8) == 'Abstract';
if ($classProperties['is_abstract'] && !$startsWithAbstract) {
$error = '%s name must begin with "Abstract"';
$phpcsFile->addError($error, $stackPtr, 'StartWithAbstract', $errorData);
}
if (!$classProperties['is_abstract'] && $startsWithAbstract) {
$error = '%s name must not begin with "Abstract"';
$phpcsFile->addError($error, $stackPtr, 'StartNotWithAbstract', $errorData);
}
}
示例2: process
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document.
* @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)
{
$properties = $phpcsFile->getClassProperties($stackPtr);
if (!$properties['is_abstract']) {
return;
}
$tokens = $phpcsFile->getTokens();
$line = $tokens[$stackPtr]['line'];
while ($tokens[$stackPtr]['line'] == $line) {
if ('T_STRING' == $tokens[$stackPtr]['type']) {
if (substr($tokens[$stackPtr]['content'], 0, 8) != 'Abstract') {
$phpcsFile->addError('Class name is not prefixed with "Abstract"', $stackPtr);
}
break;
}
$stackPtr++;
}
}