Skip to content

Commit

Permalink
SlevomatCodingStandard.Classes.DisallowMultiPropertyDefinition: Fixed…
Browse files Browse the repository at this point in the history
… false positives for old array definition style
  • Loading branch information
kukulich committed Sep 21, 2022
1 parent 82a0002 commit 2695d1c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
Expand Up @@ -11,6 +11,7 @@
use function count;
use function sprintf;
use function trim;
use const T_ARRAY;
use const T_AS;
use const T_COMMA;
use const T_FUNCTION;
Expand Down Expand Up @@ -61,7 +62,7 @@ public function process(File $phpcsFile, $visibilityPointer): void
$commaPointers = [];
$nextPointer = $propertyPointer;
do {
$nextPointer = TokenHelper::findNext($phpcsFile, [T_COMMA, T_OPEN_SHORT_ARRAY], $nextPointer + 1, $semicolonPointer);
$nextPointer = TokenHelper::findNext($phpcsFile, [T_COMMA, T_OPEN_SHORT_ARRAY, T_ARRAY], $nextPointer + 1, $semicolonPointer);

if ($nextPointer === null) {
break;
Expand All @@ -72,6 +73,11 @@ public function process(File $phpcsFile, $visibilityPointer): void
continue;
}

if ($tokens[$nextPointer]['code'] === T_ARRAY) {
$nextPointer = $tokens[$nextPointer]['parenthesis_closer'];
continue;
}

$commaPointers[] = $nextPointer;

} while (true);
Expand Down
Expand Up @@ -17,14 +17,15 @@ public function testErrors(): void
{
$report = self::checkFile(__DIR__ . '/data/disallowMultiPropertyDefinitionErrors.php');

self::assertSame(6, $report->getErrorCount());
self::assertSame(7, $report->getErrorCount());

self::assertSniffError($report, 6, DisallowMultiPropertyDefinitionSniff::CODE_DISALLOWED_MULTI_PROPERTY_DEFINITION);
self::assertSniffError($report, 8, DisallowMultiPropertyDefinitionSniff::CODE_DISALLOWED_MULTI_PROPERTY_DEFINITION);
self::assertSniffError($report, 11, DisallowMultiPropertyDefinitionSniff::CODE_DISALLOWED_MULTI_PROPERTY_DEFINITION);
self::assertSniffError($report, 13, DisallowMultiPropertyDefinitionSniff::CODE_DISALLOWED_MULTI_PROPERTY_DEFINITION);
self::assertSniffError($report, 24, DisallowMultiPropertyDefinitionSniff::CODE_DISALLOWED_MULTI_PROPERTY_DEFINITION);
self::assertSniffError($report, 26, DisallowMultiPropertyDefinitionSniff::CODE_DISALLOWED_MULTI_PROPERTY_DEFINITION);
self::assertSniffError($report, 32, DisallowMultiPropertyDefinitionSniff::CODE_DISALLOWED_MULTI_PROPERTY_DEFINITION);

self::assertAllFixedInFile($report);
}
Expand Down
Expand Up @@ -33,4 +33,6 @@ class Foo
private $b = ['b'];
private $c = ['c'];

private $aa = array('a', 'aa');
private $bb = array('b', 'bb');
}
Expand Up @@ -29,4 +29,5 @@ class Foo
$c = ['c']
;

private $aa = array('a', 'aa'), $bb = array('b', 'bb');
}
Expand Up @@ -17,6 +17,11 @@ class Foo
'c',
];

public $oldArray = array(
'a',
'b',
);

public function __construct(private string $propertyPromotion, private int $propertyPromotion2)
{
}
Expand Down

0 comments on commit 2695d1c

Please sign in to comment.