本文整理匯總了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++;
}
}