Skip to content

Commit 443bb7e

Browse files
dgkukulich
authored andcommitted
AbstractPropertyAndConstantSpacing: supports attributes
1 parent 922e946 commit 443bb7e

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

SlevomatCodingStandard/Sniffs/Classes/AbstractPropertyAndConstantSpacing.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use function assert;
1111
use function in_array;
1212
use function str_repeat;
13+
use const T_ATTRIBUTE;
1314
use const T_COMMENT;
1415
use const T_CONST;
1516
use const T_DOC_COMMENT_OPEN_TAG;
@@ -70,15 +71,15 @@ public function process(File $phpcsFile, $pointer): int
7071
return $nextFunctionPointer ?? $firstOnLinePointer;
7172
}
7273

73-
$types = [T_COMMENT, T_DOC_COMMENT_OPEN_TAG, T_CONST, T_VAR, T_PUBLIC, T_PROTECTED, T_PRIVATE, T_USE];
74+
$types = [T_COMMENT, T_DOC_COMMENT_OPEN_TAG, T_ATTRIBUTE, T_CONST, T_VAR, T_PUBLIC, T_PROTECTED, T_PRIVATE, T_USE];
7475
$nextPointer = TokenHelper::findNext($phpcsFile, $types, $firstOnLinePointer + 1, $tokens[$classPointer]['scope_closer']);
7576

7677
if (!$this->isNextMemberValid($phpcsFile, $nextPointer)) {
7778
return $nextPointer;
7879
}
7980

8081
$linesBetween = $tokens[$nextPointer]['line'] - $tokens[$semicolonPointer]['line'] - 1;
81-
if (in_array($tokens[$nextPointer]['code'], [T_DOC_COMMENT_OPEN_TAG, T_COMMENT], true)) {
82+
if (in_array($tokens[$nextPointer]['code'], [T_DOC_COMMENT_OPEN_TAG, T_COMMENT, T_ATTRIBUTE], true)) {
8283
$minExpectedLines = SniffSettingsHelper::normalizeInteger($this->minLinesCountBeforeWithComment);
8384
$maxExpectedLines = SniffSettingsHelper::normalizeInteger($this->maxLinesCountBeforeWithComment);
8485
} else {

tests/Sniffs/Classes/data/methodSpacingNoErrors.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ abstract public function secondMethod();
5151
/**
5252
* With Comment
5353
*/
54+
#[MyAttribute]
5455
public function thirdMethod()
5556
{
5657

tests/Sniffs/Classes/data/propertySpacingNoErrors.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ abstract class Bar {
4141
// strange but yeah, whatever
4242
public $foo = 'bar';
4343

44+
#[MyAttribute]
4445
/** @var string */
4546
protected $bar = 'foo';
4647

47-
/** @var int */
48+
#[MyAttribute]
4849
private $lvl = 9001;
4950
/**
5051
* whatever

0 commit comments

Comments
 (0)