diff --git a/Universal/Docs/WhiteSpace/AnonClassKeywordSpacingStandard.xml b/Universal/Docs/WhiteSpace/AnonClassKeywordSpacingStandard.xml new file mode 100644 index 00000000..4eff64c3 --- /dev/null +++ b/Universal/Docs/WhiteSpace/AnonClassKeywordSpacingStandard.xml @@ -0,0 +1,28 @@ + + + + + + + + class($param) +{ + public function __construct($p) {} +}; + ]]> + + + class ($param) +{ + public function __construct($p) {} +}; + ]]> + + + diff --git a/Universal/Sniffs/WhiteSpace/AnonClassKeywordSpacingSniff.php b/Universal/Sniffs/WhiteSpace/AnonClassKeywordSpacingSniff.php new file mode 100644 index 00000000..f823fc28 --- /dev/null +++ b/Universal/Sniffs/WhiteSpace/AnonClassKeywordSpacingSniff.php @@ -0,0 +1,83 @@ +getTokens(); + + $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); + if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS) { + return; + } + + // Check spacing + // Auto-fix when not a comment bteween. + SpacesFixer::checkAndFix( + $phpcsFile, + $stackPtr, + $nextNonEmpty, + (int) $this->spacing, + 'There must be %1$s between the class keyword and the open parenthesis for an anonymous class. Found: %2$s', + 'Incorrect', + 'error', + 0, + 'Anon class: space between keyword and open parenthesis' + ); + + // $phpcsFile->recordMetric($reportPtr, self::METRIC_NAME_SRC, 'same namespace'); + // $phpcsFile->addError($error, $reportPtr, $errorCode, $data); + } +} diff --git a/Universal/Tests/WhiteSpace/AnonClassKeywordSpacingUnitTest.inc b/Universal/Tests/WhiteSpace/AnonClassKeywordSpacingUnitTest.inc new file mode 100644 index 00000000..fc238705 --- /dev/null +++ b/Universal/Tests/WhiteSpace/AnonClassKeywordSpacingUnitTest.inc @@ -0,0 +1,103 @@ + + */ + public function getErrorList() + { + return [ + 28 => 1, + 29 => 1, + 30 => 1, + 37 => 1, + 38 => 1, + 39 => 1, + 56 => 1, + 57 => 1, + 60 => 1, + 61 => 1, + 68 => 1, + 69 => 1, + 70 => 1, + 87 => 1, + 88 => 1, + 91 => 1, + 92 => 1, + 93 => 1, + ]; + } + + /** + * Returns the lines where warnings should occur. + * + * @return array + */ + public function getWarningList() + { + return []; + } +}