clean install

This commit is contained in:
2024-12-10 15:08:16 +01:00
commit e14eb2d8fd
31193 changed files with 3555714 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
<?php
/**
* \Drupal\Sniffs\WhiteSpace\CloseBracketSpacingSniff.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
namespace Drupal\Sniffs\WhiteSpace;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Util\Tokens;
/**
* Checks that there is no white space before a closing bracket, for ")" and "}".
* Square Brackets are handled by
* \PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayBracketSpacingSniff.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class CloseBracketSpacingSniff implements Sniff
{
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array<int|string>
*/
public function register()
{
return [
T_CLOSE_CURLY_BRACKET,
T_CLOSE_PARENTHESIS,
T_CLOSE_SHORT_ARRAY,
];
}//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param \PHP_CodeSniffer\Files\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();
// Ignore curly brackets in javascript files.
if ($tokens[$stackPtr]['code'] === T_CLOSE_CURLY_BRACKET
&& $phpcsFile->tokenizerType === 'JS'
) {
return;
}
if (isset($tokens[($stackPtr - 1)]) === true
&& $tokens[($stackPtr - 1)]['code'] === T_WHITESPACE
) {
$before = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
if ($before !== false && $tokens[$stackPtr]['line'] === $tokens[$before]['line']) {
$error = 'There should be no white space before a closing "%s"';
$fix = $phpcsFile->addFixableError(
$error,
($stackPtr - 1),
'ClosingWhitespace',
[$tokens[$stackPtr]['content']]
);
if ($fix === true) {
$phpcsFile->fixer->replaceToken(($stackPtr - 1), '');
}
}
}
}//end process()
}//end class

View File

@@ -0,0 +1,85 @@
<?php
/**
* \Drupal\Sniffs\WhiteSpace\CommaSniff.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
namespace Drupal\Sniffs\WhiteSpace;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
/**
* \Drupal\Sniffs\WhiteSpace\CommaSniff.
*
* Checks that there is one space after a comma.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class CommaSniff implements Sniff
{
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array<int|string>
*/
public function register()
{
return [T_COMMA];
}//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param \PHP_CodeSniffer\Files\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();
if (isset($tokens[($stackPtr + 1)]) === false) {
return;
}
if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE
&& $tokens[($stackPtr + 1)]['code'] !== T_COMMA
&& $tokens[($stackPtr + 1)]['code'] !== T_CLOSE_PARENTHESIS
) {
$error = 'Expected one space after the comma, 0 found';
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpace');
if ($fix === true) {
$phpcsFile->fixer->addContent($stackPtr, ' ');
}
return;
}
if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE
&& isset($tokens[($stackPtr + 2)]) === true
&& $tokens[($stackPtr + 2)]['line'] === $tokens[($stackPtr + 1)]['line']
&& $tokens[($stackPtr + 1)]['content'] !== ' '
) {
$error = 'Expected one space after the comma, %s found';
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'TooManySpaces', [strlen($tokens[($stackPtr + 1)]['content'])]);
if ($fix === true) {
$phpcsFile->fixer->replaceToken(($stackPtr + 1), ' ');
}
}
}//end process()
}//end class

View File

@@ -0,0 +1,78 @@
<?php
/**
* \Drupal\Sniffs\WhiteSpace\EmptyLinesSniff.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
namespace Drupal\Sniffs\WhiteSpace;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
/**
* \Drupal\Sniffs\WhiteSpace\EmptyLinesSniff.
*
* Checks that there are not more than 2 empty lines following each other.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class EmptyLinesSniff implements Sniff
{
/**
* A list of tokenizers this sniff supports.
*
* @var array<string>
*/
public $supportedTokenizers = [
'PHP',
'JS',
'CSS',
];
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array<int|string>
*/
public function register()
{
return [T_WHITESPACE];
}//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param \PHP_CodeSniffer\Files\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();
if ($tokens[$stackPtr]['content'] === $phpcsFile->eolChar
&& isset($tokens[($stackPtr + 1)]) === true
&& $tokens[($stackPtr + 1)]['content'] === $phpcsFile->eolChar
&& isset($tokens[($stackPtr + 2)]) === true
&& $tokens[($stackPtr + 2)]['content'] === $phpcsFile->eolChar
&& isset($tokens[($stackPtr + 3)]) === true
&& $tokens[($stackPtr + 3)]['content'] === $phpcsFile->eolChar
) {
$error = 'More than 2 empty lines are not allowed';
$phpcsFile->addError($error, ($stackPtr + 3), 'EmptyLines');
}
}//end process()
}//end class

View File

@@ -0,0 +1,62 @@
<?php
/**
* \Drupal\Sniffs\WhiteSpace\NamespaceSniff.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
namespace Drupal\Sniffs\WhiteSpace;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
/**
* Checks that there is exactly one space after the namespace keyword.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class NamespaceSniff implements Sniff
{
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array<int|string>
*/
public function register()
{
return [T_NAMESPACE];
}//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param \PHP_CodeSniffer\Files\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();
if ($tokens[($stackPtr + 1)]['content'] !== ' ') {
$error = 'There must be exactly one space after the namespace keyword';
$fix = $phpcsFile->addFixableError($error, ($stackPtr + 1), 'OneSpace');
if ($fix === true) {
$phpcsFile->fixer->replaceToken(($stackPtr + 1), ' ');
}
}
}//end process()
}//end class

View File

@@ -0,0 +1,155 @@
<?php
/**
* \Drupal\Sniffs\WhiteSpace\ObjectOperatorIndentSniff.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
namespace Drupal\Sniffs\WhiteSpace;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Util\Tokens;
/**
* \Drupal\Sniffs\WhiteSpace\ObjectOperatorIndentSniff.
*
* Checks that object operators are indented 2 spaces if they are the first
* thing on a line.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class ObjectOperatorIndentSniff implements Sniff
{
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array<int|string>
*/
public function register()
{
return [T_OBJECT_OPERATOR];
}//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param \PHP_CodeSniffer\Files\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(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
// Check that there is only whitespace before the object operator and there
// is nothing else on the line.
if ($tokens[($stackPtr - 1)]['code'] !== T_WHITESPACE || $tokens[($stackPtr - 1)]['column'] !== 1) {
return;
}
$previousLine = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 2), null, true, null, true);
if ($previousLine === false) {
return;
}
// Check if the line before is in the same scope and go back if necessary.
$scopeDiff = [$previousLine => $previousLine];
$startOfLine = $stackPtr;
while (empty($scopeDiff) === false) {
// Find the first non whitespace character on the previous line.
$startOfLine = $this->findStartOfline($phpcsFile, $previousLine);
$startParenthesis = [];
if (isset($tokens[$startOfLine]['nested_parenthesis']) === true) {
$startParenthesis = $tokens[$startOfLine]['nested_parenthesis'];
}
$operatorParenthesis = [];
if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
$operatorParenthesis = $tokens[$stackPtr]['nested_parenthesis'];
}
$scopeDiff = array_diff_assoc($startParenthesis, $operatorParenthesis);
if (empty($scopeDiff) === false) {
$previousLine = key($scopeDiff);
}
}
// Closing parenthesis can be indented in several ways, so rather use the
// line that opened the parenthesis.
if ($tokens[$startOfLine]['code'] === T_CLOSE_PARENTHESIS) {
$startOfLine = $this->findStartOfline($phpcsFile, $tokens[$startOfLine]['parenthesis_opener']);
}
if ($tokens[$startOfLine]['code'] === T_OBJECT_OPERATOR) {
// If there is some wrapping in function calls then there should be an
// additional level of indentation.
if (isset($tokens[$stackPtr]['nested_parenthesis']) === true
&& (empty($tokens[$startOfLine]['nested_parenthesis']) === true
|| $tokens[$startOfLine]['nested_parenthesis'] !== $tokens[$stackPtr]['nested_parenthesis'])
) {
$additionalIndent = 2;
} else {
$additionalIndent = 0;
}
} else {
$additionalIndent = 2;
}
if ($tokens[$stackPtr]['column'] !== ($tokens[$startOfLine]['column'] + $additionalIndent)) {
$error = 'Object operator not indented correctly; expected %s spaces but found %s';
$expectedIndent = ($tokens[$startOfLine]['column'] + $additionalIndent - 1);
$data = [
$expectedIndent,
($tokens[$stackPtr]['column'] - 1),
];
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'Indent', $data);
if ($fix === true) {
$phpcsFile->fixer->replaceToken(($stackPtr - 1), str_repeat(' ', $expectedIndent));
}
}
}//end process()
/**
* Returns the first non whitespace token on the line.
*
* @param \PHP_CodeSniffer\Files\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 int
*/
protected function findStartOfline(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
// Find the first non whitespace character on the previous line.
$startOfLine = $stackPtr;
while ($tokens[($startOfLine - 1)]['line'] === $tokens[$startOfLine]['line']) {
$startOfLine--;
}
if ($tokens[$startOfLine]['code'] === T_WHITESPACE) {
$startOfLine++;
}
return $startOfLine;
}//end findStartOfline()
}//end class

View File

@@ -0,0 +1,108 @@
<?php
/**
* \Drupal\Sniffs\WhiteSpace\ObjectOperatorSpacingSniff.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
namespace Drupal\Sniffs\WhiteSpace;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Util\Tokens;
/**
* Ensure that there are no white spaces before and after the object operator.
*
* Largely copied from
* \PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\ObjectOperatorSpacingSniff
* but modified to not throw errors on multi line statements.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class ObjectOperatorSpacingSniff implements Sniff
{
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array<int|string>
*/
public function register()
{
return [T_OBJECT_OPERATOR];
}//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param \PHP_CodeSniffer\Files\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();
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);
$prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
// Line breaks are allowed before an object operator.
if ($before !== 0 && $tokens[$stackPtr]['line'] === $tokens[$prevToken]['line']) {
$error = 'Space found before object operator';
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'Before');
if ($fix === true) {
$phpcsFile->fixer->replaceToken(($stackPtr - 1), '');
}
}
if ($after !== 0) {
$error = 'Space found after object operator';
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'After');
if ($fix === true) {
if ($after === 'newline') {
// Delete the operator on this line and insert it before the
// token on the next line.
$phpcsFile->fixer->beginChangeset();
$phpcsFile->fixer->replaceToken($stackPtr, '');
$phpcsFile->fixer->addContentBefore(($stackPtr + 2), '->');
$phpcsFile->fixer->endChangeset();
} else {
$phpcsFile->fixer->replaceToken(($stackPtr + 1), '');
}
}
}
}//end process()
}//end class

View File

@@ -0,0 +1,86 @@
<?php
/**
* \Drupal\Sniffs\WhiteSpace\OpenBracketSpacingSniff.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
namespace Drupal\Sniffs\WhiteSpace;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
/**
* Checks that there is no white space after an opening bracket, for "(" and "{".
* Square Brackets are handled by
* \PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayBracketSpacingSniff.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class OpenBracketSpacingSniff implements Sniff
{
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array<int|string>
*/
public function register()
{
return [
T_OPEN_CURLY_BRACKET,
T_OPEN_PARENTHESIS,
T_OPEN_SHORT_ARRAY,
];
}//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param \PHP_CodeSniffer\Files\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();
// Ignore curly brackets in javascript files.
if ($tokens[$stackPtr]['code'] === T_OPEN_CURLY_BRACKET
&& $phpcsFile->tokenizerType === 'JS'
) {
return;
}
if (isset($tokens[($stackPtr + 1)]) === true
&& $tokens[($stackPtr + 1)]['code'] === T_WHITESPACE
&& strpos($tokens[($stackPtr + 1)]['content'], $phpcsFile->eolChar) === false
// Allow spaces in template files where the PHP close tag is used.
&& isset($tokens[($stackPtr + 2)]) === true
&& $tokens[($stackPtr + 2)]['code'] !== T_CLOSE_TAG
) {
$error = 'There should be no white space after an opening "%s"';
$fix = $phpcsFile->addFixableError(
$error,
($stackPtr + 1),
'OpeningWhitespace',
[$tokens[$stackPtr]['content']]
);
if ($fix === true) {
$phpcsFile->fixer->replaceToken(($stackPtr + 1), '');
}
}
}//end process()
}//end class

View File

@@ -0,0 +1,96 @@
<?php
/**
* \Drupal\Sniffs\WhiteSpace\OpenTagNewlineSniff.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
namespace Drupal\Sniffs\WhiteSpace;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
/**
* Checks that there is exactly one newline after the PHP open tag.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class OpenTagNewlineSniff implements Sniff
{
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array<int|string>
*/
public function register()
{
return [T_OPEN_TAG];
}//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where the
* token was found.
* @param int $stackPtr The position in the PHP_CodeSniffer
* file's token stack where the token
* was found.
*
* @return int End of the stack to skip the rest of the file.
*/
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
// Only check the very first PHP open tag in a file, ignore any others.
if ($stackPtr !== 0) {
return ($phpcsFile->numTokens + 1);
}
$next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
// If there is no further content in this file ignore it.
if ($next === false) {
return ($phpcsFile->numTokens + 1);
}
if ($tokens[$next]['line'] === 3) {
return ($phpcsFile->numTokens + 1);
}
$error = 'The PHP open tag must be followed by exactly one blank line';
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'BlankLine');
if ($fix === true) {
$phpcsFile->fixer->beginChangeset();
if ($tokens[$next]['line'] === 1) {
$phpcsFile->fixer->addNewline($stackPtr);
$phpcsFile->fixer->addNewline($stackPtr);
} else if ($tokens[$next]['line'] === 2) {
$phpcsFile->fixer->addNewline($stackPtr);
} else {
for ($i = ($stackPtr + 1); $i < $next; $i++) {
if ($tokens[$i]['line'] > 2) {
$phpcsFile->fixer->replaceToken($i, '');
}
}
}
$phpcsFile->fixer->endChangeset();
}
return ($phpcsFile->numTokens + 1);
}//end process()
}//end class

View File

@@ -0,0 +1,197 @@
<?php
/**
* \Drupal\Sniffs\WhiteSpace\ScopeClosingBraceSniff.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://Drupal.php.net/package/PHP_CodeSniffer
*/
namespace Drupal\Sniffs\WhiteSpace;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Util\Tokens;
/**
* Copied from \PHP_CodeSniffer\Standards\PEAR\Sniffs\WhiteSpace\ScopeClosingBraceSniff to allow empty methods
* and classes.
*
* Checks that the closing braces of scopes are aligned correctly.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class ScopeClosingBraceSniff implements Sniff
{
/**
* The number of spaces code should be indented.
*
* @var integer
*/
public $indent = 2;
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array<int|string>
*/
public function register()
{
return Tokens::$scopeOpeners;
}//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param \PHP_CodeSniffer\Files\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(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
// If this is an inline condition (ie. there is no scope opener), then
// return, as this is not a new scope.
if (isset($tokens[$stackPtr]['scope_closer']) === false) {
return;
}
$scopeStart = $tokens[$stackPtr]['scope_opener'];
$scopeEnd = $tokens[$stackPtr]['scope_closer'];
// If the scope closer doesn't think it belongs to this scope opener
// then the opener is sharing its closer with other tokens. We only
// want to process the closer once, so skip this one.
if (isset($tokens[$scopeEnd]['scope_condition']) === false
|| $tokens[$scopeEnd]['scope_condition'] !== $stackPtr
) {
return;
}
// We need to actually find the first piece of content on this line,
// because if this is a method with tokens before it (public, static etc)
// or an if with an else before it, then we need to start the scope
// checking from there, rather than the current token.
$lineStart = ($stackPtr - 1);
for ($lineStart; $lineStart > 0; $lineStart--) {
if (strpos($tokens[$lineStart]['content'], $phpcsFile->eolChar) !== false) {
break;
}
}
$lineStart++;
$startColumn = 1;
if ($tokens[$lineStart]['code'] === T_WHITESPACE) {
$startColumn = $tokens[($lineStart + 1)]['column'];
} else if ($tokens[$lineStart]['code'] === T_INLINE_HTML) {
$trimmed = ltrim($tokens[$lineStart]['content']);
if ($trimmed === '') {
$startColumn = $tokens[($lineStart + 1)]['column'];
} else {
$startColumn = (strlen($tokens[$lineStart]['content']) - strlen($trimmed));
}
}
// Check that the closing brace is on it's own line.
for ($lastContent = ($scopeEnd - 1); $lastContent > $scopeStart; $lastContent--) {
if ($tokens[$lastContent]['code'] === T_WHITESPACE || $tokens[$lastContent]['code'] === T_OPEN_TAG) {
continue;
}
if ($tokens[$lastContent]['code'] === T_INLINE_HTML
&& ltrim($tokens[$lastContent]['content']) === ''
) {
continue;
}
break;
}
if ($tokens[$lastContent]['line'] === $tokens[$scopeEnd]['line']) {
// Only allow empty classes and methods.
if ($tokens[$lastContent]['code'] === T_OPEN_CURLY_BRACKET) {
return;
}
$error = 'Closing brace must be on a line by itself';
$fix = $phpcsFile->addFixableError($error, $scopeEnd, 'Line');
if ($fix === true) {
$phpcsFile->fixer->addNewlineBefore($scopeEnd);
}
return;
}
// Check now that the closing brace is lined up correctly.
$lineStart = ($scopeEnd - 1);
for ($lineStart; $lineStart > 0; $lineStart--) {
if (strpos($tokens[$lineStart]['content'], $phpcsFile->eolChar) !== false) {
break;
}
}
$lineStart++;
$braceIndent = 0;
if ($tokens[$lineStart]['code'] === T_WHITESPACE) {
$braceIndent = ($tokens[($lineStart + 1)]['column'] - 1);
} else if ($tokens[$lineStart]['code'] === T_INLINE_HTML) {
$trimmed = ltrim($tokens[$lineStart]['content']);
if ($trimmed === '') {
$braceIndent = ($tokens[($lineStart + 1)]['column'] - 1);
} else {
$braceIndent = (strlen($tokens[$lineStart]['content']) - strlen($trimmed) - 1);
}
}
$fix = false;
if ($tokens[$stackPtr]['code'] === T_CASE
|| $tokens[$stackPtr]['code'] === T_DEFAULT
) {
// BREAK statements should be indented n spaces from the
// CASE or DEFAULT statement.
$expectedIndent = ($startColumn + $this->indent - 1);
if ($braceIndent !== $expectedIndent) {
$error = 'Case breaking statement indented incorrectly; expected %s spaces, found %s';
$data = [
$expectedIndent,
$braceIndent,
];
$fix = $phpcsFile->addFixableError($error, $scopeEnd, 'BreakIndent', $data);
}
} else {
$expectedIndent = max(0, ($startColumn - 1));
if ($braceIndent !== $expectedIndent) {
$error = 'Closing brace indented incorrectly; expected %s spaces, found %s';
$data = [
$expectedIndent,
$braceIndent,
];
$fix = $phpcsFile->addFixableError($error, $scopeEnd, 'Indent', $data);
}
}//end if
if ($fix === true) {
$spaces = str_repeat(' ', $expectedIndent);
if ($braceIndent === 0) {
$phpcsFile->fixer->addContentBefore($lineStart, $spaces);
} else {
$phpcsFile->fixer->replaceToken($lineStart, ltrim($tokens[$lineStart]['content']));
$phpcsFile->fixer->addContentBefore($lineStart, $spaces);
}
}
}//end process()
}//end class

File diff suppressed because it is too large Load Diff