Skip to content

Commit 4298073

Browse files
committed
Relax check for missing return type w/ null doc bloc
1 parent b713fbc commit 4298073

File tree

3 files changed

+4
-9
lines changed

3 files changed

+4
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Not released
44
- Fix false positive in `ReturnTypeDeclarationSniff` with nullable types.
5+
- Relax check for missing return type when `{aType}|null` doc bloc is present.
56
- Add `is` to the list of allowed short names.
67

78
## 0.10.0

Inpsyde/Sniffs/CodeQuality/ReturnTypeDeclarationSniff.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public function process(File $file, $position)
7373
$hasNoReturnType,
7474
$nonVoidReturnCount,
7575
$voidReturnCount,
76-
$nullReturnCount,
7776
$file,
7877
$position
7978
);
@@ -85,7 +84,6 @@ public function process(File $file, $position)
8584
* @param bool $hasNoReturnType
8685
* @param int $nonVoidReturnCount
8786
* @param int $voidReturnCount
88-
* @param int $nullReturnCount
8987
* @param File $file
9088
* @param int $position
9189
*/
@@ -95,7 +93,6 @@ private function maybeErrors(
9593
bool $hasNoReturnType,
9694
int $nonVoidReturnCount,
9795
int $voidReturnCount,
98-
int $nullReturnCount,
9996
File $file,
10097
int $position
10198
) {
@@ -126,10 +123,7 @@ private function maybeErrors(
126123
return;
127124
}
128125

129-
if ($nullReturnCount
130-
&& $nonVoidReturnCount
131-
&& ($nullReturnCount === $voidReturnCount)
132-
&& !$this->areNullableReturnTypesSupported()
126+
if (!$this->areNullableReturnTypesSupported()
133127
&& $this->hasReturnNullDocBloc($file, $position)
134128
) {
135129
return;

tests/fixtures/return-type-declaration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public function iMaybeReturnNull()
252252
/**
253253
* @return \ArrayAccess|null
254254
*/
255-
public function iShouldReturnNullButReturnVoid() // @phpcsWarningCodeOnThisLine NoReturnType
255+
public function iShouldReturnNullButReturnVoid()
256256
{
257257
if (rand(1, 4) === 3) {
258258
return null;
@@ -268,7 +268,7 @@ public function iShouldReturnNullButReturnVoid() // @phpcsWarningCodeOnThisLine
268268
/**
269269
* @return \ArrayAccess|null
270270
*/
271-
public function iShouldReturnNull() // @phpcsWarningCodeOnThisLine NoReturnType
271+
public function iShouldReturnNull()
272272
{
273273
return new \ArrayObject();
274274
}

0 commit comments

Comments
 (0)