Skip to content

Commit

Permalink
AbstractPropertyAndConstantSpacing: supports attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
dg authored and kukulich committed Apr 27, 2021
1 parent 922e946 commit 443bb7e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,15 +71,15 @@ 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)) {
return $nextPointer;
}

$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 {
Expand Down
1 change: 1 addition & 0 deletions tests/Sniffs/Classes/data/methodSpacingNoErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ abstract public function secondMethod();
/**
* With Comment
*/
#[MyAttribute]
public function thirdMethod()
{

Expand Down
3 changes: 2 additions & 1 deletion tests/Sniffs/Classes/data/propertySpacingNoErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 443bb7e

Please sign in to comment.