From 443bb7eaab39cfef7a1be05fe33ff3ac4fe020f8 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 27 Apr 2021 13:48:22 +0200 Subject: [PATCH] AbstractPropertyAndConstantSpacing: supports attributes --- .../Sniffs/Classes/AbstractPropertyAndConstantSpacing.php | 5 +++-- tests/Sniffs/Classes/data/methodSpacingNoErrors.php | 1 + tests/Sniffs/Classes/data/propertySpacingNoErrors.php | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/SlevomatCodingStandard/Sniffs/Classes/AbstractPropertyAndConstantSpacing.php b/SlevomatCodingStandard/Sniffs/Classes/AbstractPropertyAndConstantSpacing.php index a59f4ba77..bdf806ba9 100644 --- a/SlevomatCodingStandard/Sniffs/Classes/AbstractPropertyAndConstantSpacing.php +++ b/SlevomatCodingStandard/Sniffs/Classes/AbstractPropertyAndConstantSpacing.php @@ -10,6 +10,7 @@ use function assert; use function in_array; use function str_repeat; +use const T_ATTRIBUTE; use const T_COMMENT; use const T_CONST; use const T_DOC_COMMENT_OPEN_TAG; @@ -70,7 +71,7 @@ public function process(File $phpcsFile, $pointer): int return $nextFunctionPointer ?? $firstOnLinePointer; } - $types = [T_COMMENT, T_DOC_COMMENT_OPEN_TAG, T_CONST, T_VAR, T_PUBLIC, T_PROTECTED, T_PRIVATE, T_USE]; + $types = [T_COMMENT, T_DOC_COMMENT_OPEN_TAG, T_ATTRIBUTE, T_CONST, T_VAR, T_PUBLIC, T_PROTECTED, T_PRIVATE, T_USE]; $nextPointer = TokenHelper::findNext($phpcsFile, $types, $firstOnLinePointer + 1, $tokens[$classPointer]['scope_closer']); if (!$this->isNextMemberValid($phpcsFile, $nextPointer)) { @@ -78,7 +79,7 @@ public function process(File $phpcsFile, $pointer): int } $linesBetween = $tokens[$nextPointer]['line'] - $tokens[$semicolonPointer]['line'] - 1; - if (in_array($tokens[$nextPointer]['code'], [T_DOC_COMMENT_OPEN_TAG, T_COMMENT], true)) { + if (in_array($tokens[$nextPointer]['code'], [T_DOC_COMMENT_OPEN_TAG, T_COMMENT, T_ATTRIBUTE], true)) { $minExpectedLines = SniffSettingsHelper::normalizeInteger($this->minLinesCountBeforeWithComment); $maxExpectedLines = SniffSettingsHelper::normalizeInteger($this->maxLinesCountBeforeWithComment); } else { diff --git a/tests/Sniffs/Classes/data/methodSpacingNoErrors.php b/tests/Sniffs/Classes/data/methodSpacingNoErrors.php index cf86f52a2..11e737bda 100644 --- a/tests/Sniffs/Classes/data/methodSpacingNoErrors.php +++ b/tests/Sniffs/Classes/data/methodSpacingNoErrors.php @@ -51,6 +51,7 @@ abstract public function secondMethod(); /** * With Comment */ + #[MyAttribute] public function thirdMethod() { diff --git a/tests/Sniffs/Classes/data/propertySpacingNoErrors.php b/tests/Sniffs/Classes/data/propertySpacingNoErrors.php index 2797e7b32..92f90d135 100644 --- a/tests/Sniffs/Classes/data/propertySpacingNoErrors.php +++ b/tests/Sniffs/Classes/data/propertySpacingNoErrors.php @@ -41,10 +41,11 @@ abstract class Bar { // strange but yeah, whatever public $foo = 'bar'; + #[MyAttribute] /** @var string */ protected $bar = 'foo'; - /** @var int */ + #[MyAttribute] private $lvl = 9001; /** * whatever