Skip to content

Commit c463fc0

Browse files
committed
Squiz/ScopeKeywordSpacing: update for properties with asymmetric visibility
Prevent false negatives for the "incorrect space after keyword" error. Includes tests.
1 parent 2e9da03 commit c463fc0

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ class ScopeKeywordSpacingSniff implements Sniff
2424
*/
2525
public function register()
2626
{
27-
$register = Tokens::$methodPrefixes;
28-
$register[] = T_READONLY;
27+
$register = Tokens::$methodPrefixes;
28+
$register += Tokens::$scopeModifiers;
29+
$register[T_READONLY] = T_READONLY;
2930
return $register;
3031

3132
}//end register()

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,13 @@ class FinalProperties {
192192
final readonly public ?MyType $spacing_correct;
193193
protected final $spacing_incorrect = 'foo';
194194
}
195+
196+
class AsymVisibility {
197+
public(set) string $asymPublic = 'hello';
198+
public protected(set) final $asymProtected = 'hello';
199+
private(set) public string|false $asymPrivate = 'hello';
200+
201+
public public(set) $asymPublicPublic = 'hello';
202+
protected(set) public $asymPublicProtected = 'hello';
203+
protected private(set) $asymProtectedPrivate = 'hello';
204+
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,13 @@ class FinalProperties {
185185
final readonly public ?MyType $spacing_correct;
186186
protected final $spacing_incorrect = 'foo';
187187
}
188+
189+
class AsymVisibility {
190+
public(set) string $asymPublic = 'hello';
191+
public protected(set) final $asymProtected = 'hello';
192+
private(set) public string|false $asymPrivate = 'hello';
193+
194+
public public(set) $asymPublicPublic = 'hello';
195+
protected(set) public $asymPublicProtected = 'hello';
196+
protected private(set) $asymProtectedPrivate = 'hello';
197+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public function getErrorList($testFile='')
7070
187 => 1,
7171
188 => 1,
7272
193 => 2,
73+
197 => 1,
74+
198 => 3,
75+
199 => 2,
7376
];
7477

7578
case 'ScopeKeywordSpacingUnitTest.3.inc':

0 commit comments

Comments
 (0)