本文整理汇总了PHP中PHP_CodeSniffer_File::recordMetric方法的典型用法代码示例。如果您正苦于以下问题:PHP PHP_CodeSniffer_File::recordMetric方法的具体用法?PHP PHP_CodeSniffer_File::recordMetric怎么用?PHP PHP_CodeSniffer_File::recordMetric使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHP_CodeSniffer_File
的用法示例。
在下文中一共展示了PHP_CodeSniffer_File::recordMetric方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
if ($tokens[$stackPtr - 1]['code'] !== T_WHITESPACE) {
$before = 0;
} else {
if ($tokens[$stackPtr - 2]['line'] !== $tokens[$stackPtr]['line']) {
$before = 'newline';
} else {
$before = $tokens[$stackPtr - 1]['length'];
}
}
if ($tokens[$stackPtr + 1]['code'] !== T_WHITESPACE) {
$after = 0;
} else {
if ($tokens[$stackPtr + 2]['line'] !== $tokens[$stackPtr]['line']) {
$after = 'newline';
} else {
$after = $tokens[$stackPtr + 1]['length'];
}
}
$phpcsFile->recordMetric($stackPtr, 'Spacing before object operator', $before);
$phpcsFile->recordMetric($stackPtr, 'Spacing after object operator', $after);
if ($before !== 0) {
$error = 'Space found before object operator';
$phpcsFile->addError($error, $stackPtr, 'Before');
}
if ($after !== 0) {
$error = 'Space found after object operator';
$phpcsFile->addError($error, $stackPtr, 'After');
}
}
示例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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$firstContent = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
// If the first non-whitespace token is not an opening parenthesis, then we are not concerned.
if ($tokens[$firstContent]['code'] !== T_OPEN_PARENTHESIS) {
$phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'no');
return;
}
$end = $phpcsFile->findNext(array(T_SEMICOLON, T_CLOSE_TAG), $stackPtr, null, false);
// If the token before the semi-colon is not a closing parenthesis, then we are not concerned.
$prev = $phpcsFile->findPrevious(T_WHITESPACE, $end - 1, null, true);
if ($tokens[$prev]['code'] !== T_CLOSE_PARENTHESIS) {
$phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'no');
return;
}
// If the parenthesis don't match, then we are not concerned.
if ($tokens[$firstContent]['parenthesis_closer'] !== $prev) {
$phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'no');
return;
}
$phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'yes');
if ($phpcsFile->findNext(PHP_CodeSniffer_Tokens::$operators, $stackPtr, $end, false) === false) {
// There are no arithmetic operators in this.
$error = 'Echoed strings should not be bracketed';
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'HasBracket');
if ($fix === true) {
$phpcsFile->fixer->beginChangeset();
$phpcsFile->fixer->replaceToken($firstContent, '');
$phpcsFile->fixer->replaceToken($end - 1, '');
$phpcsFile->fixer->endChangeset();
}
}
}
示例3: 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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$find = PHP_CodeSniffer_Tokens::$methodPrefixes;
$find[] = T_WHITESPACE;
$commentEnd = $phpcsFile->findPrevious($find, $stackPtr - 1, null, true);
if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG && $tokens[$commentEnd]['code'] !== T_COMMENT) {
$phpcsFile->addError('Missing class doc comment', $stackPtr, 'Missing');
$phpcsFile->recordMetric($stackPtr, 'Class has doc comment', 'no');
return;
}
$phpcsFile->recordMetric($stackPtr, 'Class has doc comment', 'yes');
if ($tokens[$commentEnd]['code'] === T_COMMENT) {
$phpcsFile->addError('You must use "/**" style comments for a class comment', $stackPtr, 'WrongStyle');
return;
}
if ($tokens[$commentEnd]['line'] !== $tokens[$stackPtr]['line'] - 1) {
$error = 'There must be no blank lines after the class comment';
$phpcsFile->addError($error, $commentEnd, 'SpacingAfter');
}
$commentStart = $tokens[$commentEnd]['comment_opener'];
foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
$error = '%s tag is not allowed in class comment';
$data = array($tokens[$tag]['content']);
$phpcsFile->addWarning($error, $tag, 'TagNotAllowed', $data);
}
}
示例4: process
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param integer $stackPtr The position of the current token in
* the token stack.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
if ($this->_phpVersion === null) {
$this->_phpVersion = PHP_CodeSniffer::getConfigData('php_version');
if ($this->_phpVersion === null) {
$this->_phpVersion = PHP_VERSION_ID;
}
}
$tokens = $phpcsFile->getTokens();
if (isset($tokens[$stackPtr]['scope_closer']) === false) {
return;
}
$errorData = array(strtolower($tokens[$stackPtr]['content']));
$nextClass = $phpcsFile->findNext(array(T_CLASS, T_INTERFACE, T_TRAIT), $tokens[$stackPtr]['scope_closer'] + 1);
if ($nextClass !== false) {
$error = 'Each %s must be in a file by itself';
$phpcsFile->addError($error, $nextClass, 'MultipleClasses', $errorData);
$phpcsFile->recordMetric($stackPtr, 'One class per file', 'no');
} else {
$phpcsFile->recordMetric($stackPtr, 'One class per file', 'yes');
}
if ($this->_phpVersion >= 50300) {
$namespace = $phpcsFile->findNext(array(T_NAMESPACE, T_CLASS, T_INTERFACE, T_TRAIT), 0);
if ($tokens[$namespace]['code'] !== T_NAMESPACE) {
$error = 'Each %s must be in a namespace of at least one level (a top-level vendor name)';
$phpcsFile->addError($error, $stackPtr, 'MissingNamespace', $errorData);
$phpcsFile->recordMetric($stackPtr, 'Class defined in namespace', 'no');
} else {
$phpcsFile->recordMetric($stackPtr, 'Class defined in namespace', 'yes');
}
}
}
示例5: 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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$openTag = $tokens[$stackPtr];
if ($openTag['content'] === '<?') {
$error = 'Short PHP opening tag used; expected "<?php" but found "%s"';
$data = array($openTag['content']);
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data);
if ($fix === true) {
$phpcsFile->fixer->replaceToken($stackPtr, '<?php');
}
$phpcsFile->recordMetric($stackPtr, 'PHP short open tag used', 'yes');
} else {
$phpcsFile->recordMetric($stackPtr, 'PHP short open tag used', 'no');
}
if ($openTag['code'] === T_OPEN_TAG_WITH_ECHO) {
$nextVar = $tokens[$phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true)];
$error = 'Short PHP opening tag used with echo; expected "<?php echo %s ..." but found "%s %s ..."';
$data = array($nextVar['content'], $openTag['content'], $nextVar['content']);
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'EchoFound', $data);
if ($fix === true) {
if ($tokens[$stackPtr + 1]['code'] !== T_WHITESPACE) {
$phpcsFile->fixer->replaceToken($stackPtr, '<?php echo ');
} else {
$phpcsFile->fixer->replaceToken($stackPtr, '<?php echo');
}
}
}
}
示例6: processTokenWithinScope
/**
* Processes the tokens within the scope.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being processed.
* @param int $stackPtr The position where this token was
* found.
* @param int $currScope The position of the current scope.
*
* @return void
*/
protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
{
$methodName = $phpcsFile->getDeclarationName($stackPtr);
if ($methodName === null) {
// Ignore closures.
return;
}
$className = $phpcsFile->getDeclarationName($currScope);
$errorData = array($className . '::' . $methodName);
// Is this a magic method. i.e., is prefixed with "__" ?
if (preg_match('|^__|', $methodName) !== 0) {
$magicPart = strtolower(substr($methodName, 2));
if (isset($this->magicMethods[$magicPart]) === false && isset($this->methodsDoubleUnderscore[$magicPart]) === false) {
$error = 'Method name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore';
$phpcsFile->addError($error, $stackPtr, 'MethodDoubleUnderscore', $errorData);
}
return;
}
$methodProps = $phpcsFile->getMethodProperties($stackPtr);
if (PHP_CodeSniffer::isCamelCaps($methodName, false, true, $this->strict) === false) {
if ($methodProps['scope_specified'] === true) {
$error = '%s method name "%s" is not in lowerCamel format';
$data = array(ucfirst($methodProps['scope']), $errorData[0]);
$phpcsFile->addError($error, $stackPtr, 'ScopeNotCamelCaps', $data);
} else {
$error = 'Method name "%s" is not in lowerCamel format';
$phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData);
}
$phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'no');
return;
} else {
$phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'yes');
}
}
示例7: 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)
{
$tokens = $phpcsFile->getTokens();
for ($i = $stackPtr + 1; $i < $phpcsFile->numTokens; $i++) {
if ($tokens[$i]['column'] !== 1 || $tokens[$i]['code'] !== T_WHITESPACE && $tokens[$i]['code'] !== T_DOC_COMMENT_WHITESPACE && $tokens[$i]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
continue;
}
// If tabs are being converted to spaces, the original content
// should be used instead of the converted content.
if (isset($tokens[$i]['orig_content']) === true) {
$content = $tokens[$i]['orig_content'];
} else {
$content = $tokens[$i]['content'];
}
if ($content[0] === ' ') {
if ($tokens[$i]['code'] === T_DOC_COMMENT_WHITESPACE && $content === ' ') {
// Ignore file/class-level DocBlock.
continue;
}
// Space are considered ok if they are proceeded by tabs and not followed
// by tabs, as is the case with standard docblock comments.
$error = 'Tabs must be used to indent lines; spaces are not allowed';
$phpcsFile->addError($error, $i, 'SpacesUsed');
$phpcsFile->recordMetric($i, 'Line indent', 'spaces');
} else {
if ($content[0] === "\t") {
$phpcsFile->recordMetric($i, 'Line indent', 'tabs');
}
}
}
//end for
// Ignore the rest of the file.
return $phpcsFile->numTokens + 1;
}
示例8: processTokenWithinScope
/**
* Processes the tokens within the scope.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being processed.
* @param int $stackPtr The position where this token was
* found.
* @param int $currScope The position of the current scope.
*
* @return void
*/
protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
{
$methodName = $phpcsFile->getDeclarationName($stackPtr);
if ($methodName === null) {
// Ignore closures.
return;
}
// Ignore magic methods.
if (preg_match('|^__|', $methodName) !== 0) {
$magicPart = strtolower(substr($methodName, 2));
if (isset($this->magicMethods[$magicPart]) === true || isset($this->methodsDoubleUnderscore[$magicPart]) === true) {
return;
}
}
$testName = ltrim($methodName, '_');
if (PHP_CodeSniffer::isCamelCaps($testName, false, true, false) === false) {
$error = 'Method name "%s" is not in camel caps format';
$className = $phpcsFile->getDeclarationName($currScope);
$errorData = array($className . '::' . $methodName);
$phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData);
$phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'no');
} else {
$phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'yes');
}
}
示例9: 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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$prev = $phpcsFile->findPrevious(T_SEMICOLON, $stackPtr - 1);
if ($prev === false) {
$phpcsFile->recordMetric($stackPtr, 'Multiple statements on same line', 'no');
return;
}
// Ignore multiple statements in a FOR condition.
if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
foreach ($tokens[$stackPtr]['nested_parenthesis'] as $bracket) {
if (isset($tokens[$bracket]['parenthesis_owner']) === false) {
// Probably a closure sitting inside a function call.
continue;
}
$owner = $tokens[$bracket]['parenthesis_owner'];
if ($tokens[$owner]['code'] === T_FOR) {
return;
}
}
}
if ($tokens[$prev]['line'] === $tokens[$stackPtr]['line']) {
$error = 'Each PHP statement must be on a line by itself';
$phpcsFile->addError($error, $stackPtr, 'SameLine');
$phpcsFile->recordMetric($stackPtr, 'Multiple statements on same line', 'yes');
} else {
$phpcsFile->recordMetric($stackPtr, 'Multiple statements on same line', 'no');
}
}
示例10: processTokenOutsideScope
/**
* Processes the tokens outside the scope.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being processed.
* @param int $stackPtr The position where this token was found.
*/
protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$functionName = $phpcsFile->getDeclarationName($stackPtr);
if ($functionName === null) {
// Ignore closures.
return;
}
$errorData = [$functionName];
// Is this a magic function. i.e., it is prefixed with "__".
if (preg_match('|^__|', $functionName) !== 0) {
$magicPart = strtolower(substr($functionName, 2));
if (isset($this->magicFunctions[$magicPart]) === false) {
$error = 'Function name "%s" is invalid; only PHP magic methods' . ' should be prefixed with a double underscore';
$phpcsFile->addError($error, $stackPtr, 'FunctionDoubleUnderscore', $errorData);
}
return;
}
// Ignore first underscore in functions prefixed with "_".
$functionName = ltrim($functionName, '_');
if (preg_match('/^[a-z][_a-z]*$/', $functionName) === false) {
$error = 'Function name "%s" is not in snake case format';
$phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData);
$phpcsFile->recordMetric($stackPtr, 'snake_case function name', 'no');
} else {
$phpcsFile->recordMetric($stackPtr, 'snake_case method name', 'yes');
}
}
示例11: process
/**
* Processes this sniff, 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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
// Make sure this file only contains PHP code.
for ($i = 0; $i < $phpcsFile->numTokens; $i++) {
if ($tokens[$i]['code'] === T_INLINE_HTML && trim($tokens[$i]['content']) !== '') {
return $phpcsFile->numTokens;
}
}
// Find the last non-empty token.
for ($last = $phpcsFile->numTokens - 1; $last > 0; $last--) {
if (trim($tokens[$last]['content']) !== '') {
break;
}
}
if ($tokens[$last]['code'] === T_CLOSE_TAG) {
$error = 'A closing tag is not permitted at the end of a PHP file';
$fix = $phpcsFile->addFixableError($error, $last, 'NotAllowed');
if ($fix === true) {
$phpcsFile->fixer->replaceToken($last, '');
}
$phpcsFile->recordMetric($stackPtr, 'PHP closing tag at end of PHP-only file', 'yes');
} else {
$phpcsFile->recordMetric($stackPtr, 'PHP closing tag at end of PHP-only file', 'no');
}
// Ignore the rest of the file.
return $phpcsFile->numTokens;
}
示例12: 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();
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
$error = 'Possible parse error: %s missing opening or closing brace';
$data = array($tokens[$stackPtr]['content']);
$phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $data);
return;
}
// Determine the name of the class or interface. Note that we cannot
// simply look for the first T_STRING because a class name
// starting with the number will be multiple tokens.
$opener = $tokens[$stackPtr]['scope_opener'];
$nameStart = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, $opener, true);
$nameEnd = $phpcsFile->findNext(T_WHITESPACE, $nameStart, $opener);
$name = trim($phpcsFile->getTokensAsString($nameStart, $nameEnd - $nameStart));
// Check for camel caps format.
$valid = PHP_CodeSniffer::isCamelCaps($name, true, true, false);
if ($valid === false) {
$type = ucfirst($tokens[$stackPtr]['content']);
$error = '%s name "%s" is not in camel caps format';
$data = array($type, $name);
$phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $data);
$phpcsFile->recordMetric($stackPtr, 'CamelCase class name', 'no');
} else {
$phpcsFile->recordMetric($stackPtr, 'CamelCase class name', 'yes');
}
}
示例13: 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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$this->currentFile = $phpcsFile;
$tokens = $phpcsFile->getTokens();
$type = strtolower($tokens[$stackPtr]['content']);
$errorData = array($type);
$find = PHP_CodeSniffer_Tokens::$methodPrefixes;
$find[] = T_WHITESPACE;
$commentEnd = $phpcsFile->findPrevious($find, $stackPtr - 1, null, true);
if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG && $tokens[$commentEnd]['code'] !== T_COMMENT) {
$phpcsFile->addError('Missing class doc comment', $stackPtr, 'Missing');
$phpcsFile->recordMetric($stackPtr, 'Class has doc comment', 'no');
return;
} else {
$phpcsFile->recordMetric($stackPtr, 'Class has doc comment', 'yes');
}
// Try and determine if this is a file comment instead of a class comment.
// We assume that if this is the first comment after the open PHP tag, then
// it is most likely a file comment instead of a class comment.
if ($tokens[$commentEnd]['code'] === T_DOC_COMMENT_CLOSE_TAG) {
$start = $tokens[$commentEnd]['comment_opener'] - 1;
} else {
$start = $phpcsFile->findPrevious(T_COMMENT, $commentEnd - 1, null, true);
}
if ($tokens[$commentEnd]['code'] === T_COMMENT) {
$phpcsFile->addError('You must use "/**" style comments for a class comment', $stackPtr, 'WrongStyle');
return;
}
// Check each tag.
$this->processTags($phpcsFile, $stackPtr, $tokens[$commentEnd]['comment_opener']);
}
示例14: 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)
{
$tokens = $phpcsFile->getTokens();
for ($i = $stackPtr + 1; $i < $phpcsFile->numTokens; $i++) {
if ($tokens[$i]['column'] !== 1 || $tokens[$i]['code'] !== T_WHITESPACE) {
continue;
}
if ($tokens[$i]['content'][0] === "\t") {
$error = 'Spaces must be used to indent lines; tabs are not allowed';
$fix = $phpcsFile->addFixableError($error, $i, 'TabsUsed');
$phpcsFile->recordMetric($i, 'Line indent', 'tabs');
if ($fix === true && $phpcsFile->fixer->enabled === true) {
// Replace tabs with spaces, usign an indent of 4 spaces.
// Other sniffs can then correct the indent if they need to.
$newContent = str_replace("\t", ' ', $tokens[$i]['content']);
$phpcsFile->fixer->replaceToken($i, $newContent);
}
} else {
if ($tokens[$i]['content'][0] === ' ') {
$phpcsFile->recordMetric($i, 'Line indent', 'spaces');
}
}
}
// Ignore the rest of the file.
return $phpcsFile->numTokens + 1;
}
示例15: process
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param integer $stackPtr The position of the current token in
* the token stack.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
if (isset($tokens[$stackPtr]['scope_closer']) === false) {
return;
}
$className = $phpcsFile->getDeclarationName($stackPtr);
$errorData = array(strtolower($tokens[$stackPtr]['content']));
$nextClass = $phpcsFile->findNext(array(T_CLASS, T_INTERFACE, T_TRAIT), $tokens[$stackPtr]['scope_closer'] + 1);
if ($nextClass !== false) {
$nextClassName = $phpcsFile->getDeclarationName($nextClass);
$extends = $phpcsFile->findExtendedClassName($nextClass);
if ($className == $nextClassName && $extends != $className && substr($extends, -1 * (strlen($className) + 1)) == '\\' . $className) {
// $nextClassName wraps $className in global namespace (probably)
$phpcsFile->recordMetric($stackPtr, 'One class per file', 'yes');
} else {
$error = 'Each %s must be in a file by itself';
$phpcsFile->addError($error, $nextClass, 'MultipleClasses', $errorData);
$phpcsFile->recordMetric($stackPtr, 'One class per file', 'no');
}
} else {
$phpcsFile->recordMetric($stackPtr, 'One class per file', 'yes');
}
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
$namespace = $phpcsFile->findNext(array(T_NAMESPACE, T_CLASS, T_INTERFACE, T_TRAIT), 0);
if ($tokens[$namespace]['code'] !== T_NAMESPACE) {
$error = 'Each %s must be in a namespace of at least one level (a top-level vendor name)';
$phpcsFile->addWarning($error, $stackPtr, 'MissingNamespace', $errorData);
$phpcsFile->recordMetric($stackPtr, 'Class defined in namespace', 'no');
} else {
$phpcsFile->recordMetric($stackPtr, 'Class defined in namespace', 'yes');
}
}
}