8 use PHP_CodeSniffer\Sniffs\Sniff;
9 use PHP_CodeSniffer\Files\File;
33 private $properties = [];
40 private $styleSymbolsToSkip = [
48 public function register()
52 T_CLOSE_CURLY_BRACKET,
62 public function process(File $phpcsFile, $stackPtr)
64 $tokens = $phpcsFile->getTokens();
65 $currentToken =
$tokens[$stackPtr];
68 if ((T_ASPERAND ===
$tokens[$stackPtr - 1][
'code'])
69 || in_array(
$tokens[$stackPtr][
'content'], $this->styleSymbolsToSkip)
74 $nextCurlyBracket = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, $stackPtr + 1);
75 if (in_array($currentToken[
'code'], [T_OPEN_CURLY_BRACKET, T_CLOSE_CURLY_BRACKET])
76 || ((
false !== $nextCurlyBracket) && (
$tokens[$nextCurlyBracket][
'line'] ===
$tokens[$stackPtr][
'line']))
78 if ($this->properties) {
80 $this->validatePropertiesSorting($phpcsFile, $stackPtr, $this->properties);
83 $this->properties = [];
87 if (T_STYLE === $currentToken[
'code']) {
88 $this->properties[] = $currentToken[
'content'];
101 private function validatePropertiesSorting(File $phpcsFile, $stackPtr, array $properties)
104 $symbolsForSkip = [
'(',
'block',
'field'];
107 function ($var) use ($symbolsForSkip) {
108 return !in_array($var, $symbolsForSkip);
115 if ($originalProperties !== $properties) {
116 $delimiter = $phpcsFile->findPrevious(T_SEMICOLON, $stackPtr);
117 $phpcsFile->addError(
'Properties sorted not alphabetically', $delimiter,
'PropertySorting');
process(File $phpcsFile, $stackPtr)