Skip to content

Commit 2bd19c2

Browse files
committed
Fixed bug #3277 : Nullable static return typehint causes whitespace error
1 parent 18c27ed commit 2bd19c2

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
143143
- Fixed bug #3258 : Squiz.Formatting.OperatorBracket duplicate error messages for unary minus
144144
-- Thanks to Juliette Reinders Folmer for the patch
145145
- Fixed bug #3273 : Squiz.Functions.FunctionDeclarationArgumentSpacing reports line break as 0 spaces between parenthesis
146+
- Fixed bug #3277 : Nullable static return typehint causes whitespace error
146147
</notes>
147148
<contents>
148149
<dir name="/">

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ public function process(File $phpcsFile, $stackPtr)
6666
return;
6767
}
6868

69+
if ($prevToken !== false
70+
&& $tokens[$prevToken]['code'] === T_NULLABLE
71+
) {
72+
// Not a scope keyword, but a return type.
73+
return;
74+
}
75+
6976
if ($prevToken !== false
7077
&& $tokens[$prevToken]['code'] === T_COLON
7178
) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ public static function fCreate($attributes = []): static
8989
return static::factory()->create($attributes);
9090
}
9191

92+
public static function fCreate($attributes = []): ?static
93+
{
94+
return static::factory()->create($attributes);
95+
}
96+
9297
// Also account for static used within union types.
9398
public function fCreate($attributes = []): object|static
9499
{

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ public static function fCreate($attributes = []): static
8484
return static::factory()->create($attributes);
8585
}
8686

87+
public static function fCreate($attributes = []): ?static
88+
{
89+
return static::factory()->create($attributes);
90+
}
91+
8792
// Also account for static used within union types.
8893
public function fCreate($attributes = []): object|static
8994
{

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public function getErrorList()
3838
64 => 1,
3939
67 => 1,
4040
71 => 1,
41-
98 => 1,
42-
101 => 1,
41+
103 => 1,
4342
106 => 1,
44-
114 => 1,
45-
116 => 1,
46-
122 => 2,
43+
111 => 1,
44+
119 => 1,
45+
121 => 1,
46+
127 => 2,
4747
];
4848

4949
}//end getErrorList()

0 commit comments

Comments
 (0)