Skip to content

Commit f4d7fdd

Browse files
committed
Squiz/MemberVarSpacing: update for properties with asymmetric visibility
Allow for the sniff to calculate the "lines before" correctly when asym visibility is used Includes tests.
1 parent 8fab89f commit f4d7fdd

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

src/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ protected function processMemberVar(File $phpcsFile, $stackPtr)
5353

5454
$endOfPreviousStatement = $phpcsFile->findPrevious($stopPoints, ($stackPtr - 1), null, false, null, true);
5555

56-
$validPrefixes = Tokens::$methodPrefixes;
56+
$validPrefixes = Tokens::$scopeModifiers;
57+
$validPrefixes[] = T_STATIC;
58+
$validPrefixes[] = T_FINAL;
5759
$validPrefixes[] = T_VAR;
5860
$validPrefixes[] = T_READONLY;
5961

src/Standards/Squiz/Tests/WhiteSpace/MemberVarSpacingUnitTest.1.inc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,3 +444,18 @@ class MultilineCommentShouldNotBeSplitUp {
444444
*/
445445
public $prop;
446446
}
447+
448+
class AsymVisibility {
449+
protected private(set) int $asymProtectedPrivate;
450+
451+
/**
452+
* Docblock
453+
*/
454+
protected(set) final string $asymProtected;
455+
#[AnAttribute]
456+
457+
public(set) string|bool $asymPublic;
458+
459+
460+
private(set) private bool $asymPrivate;
461+
}

src/Standards/Squiz/Tests/WhiteSpace/MemberVarSpacingUnitTest.1.inc.fixed

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,3 +431,18 @@ class MultilineCommentShouldNotBeSplitUp {
431431
*/
432432
public $prop;
433433
}
434+
435+
class AsymVisibility {
436+
437+
protected private(set) int $asymProtectedPrivate;
438+
439+
/**
440+
* Docblock
441+
*/
442+
protected(set) final string $asymProtected;
443+
444+
#[AnAttribute]
445+
public(set) string|bool $asymPublic;
446+
447+
private(set) private bool $asymPrivate;
448+
}

src/Standards/Squiz/Tests/WhiteSpace/MemberVarSpacingUnitTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ public function getErrorList($testFile='')
8787
427 => 1,
8888
437 => 1,
8989
445 => 1,
90+
449 => 1,
91+
456 => 1,
92+
457 => 1,
93+
460 => 1,
9094
];
9195

9296
default:

0 commit comments

Comments
 (0)