Skip to content

Commit ab76a87

Browse files
committed
Nicer code
1 parent 6115511 commit ab76a87

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

src/Rules/TooWideTypehints/TooWideTypeCheck.php

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,18 @@ public function checkFunctionReturnType(
177177
$unionMessagePattern = sprintf('%s never returns %%s so it can be removed from the return type.', $functionDescription);
178178
$boolMessagePattern = sprintf('%s never returns %%s so the return type can be changed to %%s.', $functionDescription);
179179

180+
// Do not require to have @return null/true/false in descendant classes
181+
if (
182+
$checkDescendantClass
183+
&& ($returnType->isNull()->yes() || $returnType->isTrue()->yes() || $returnType->isFalse()->yes())
184+
) {
185+
return [];
186+
}
187+
180188
if (!$phpDocFunctionReturnType instanceof MixedType || $phpDocFunctionReturnType->isExplicitMixed()) {
181189
$phpDocFunctionReturnType = TypeUtils::resolveLateResolvableTypes(TypehintHelper::decideType($nativeFunctionReturnType, $phpDocFunctionReturnType));
182190

183-
// Do not require to have @return null/true/false in descendant classes
184-
if (
185-
$checkDescendantClass
186-
&& ($returnType->isNull()->yes() || $returnType->isTrue()->yes() || $returnType->isFalse()->yes())
187-
) {
188-
$narrowedPhpDocType = $phpDocFunctionReturnType;
189-
} else {
190-
$narrowedPhpDocType = $this->narrowType($phpDocFunctionReturnType, $returnType, $scope, false);
191-
}
192-
191+
$narrowedPhpDocType = $this->narrowType($phpDocFunctionReturnType, $returnType, $scope, false);
193192
if (!$narrowedPhpDocType->equals($phpDocFunctionReturnType)) {
194193
return $this->createErrors(
195194
$narrowedPhpDocType,
@@ -205,16 +204,7 @@ public function checkFunctionReturnType(
205204
return [];
206205
}
207206

208-
// Do not require to have @return null/true/false in descendant classes
209-
if (
210-
$checkDescendantClass
211-
&& ($returnType->isNull()->yes() || $returnType->isTrue()->yes() || $returnType->isFalse()->yes())
212-
) {
213-
$narrowedNativeType = $nativeFunctionReturnType;
214-
} else {
215-
$narrowedNativeType = $this->narrowType($nativeFunctionReturnType, $returnType, $scope, true);
216-
}
217-
207+
$narrowedNativeType = $this->narrowType($nativeFunctionReturnType, $returnType, $scope, true);
218208
if (!$narrowedNativeType->equals($nativeFunctionReturnType)) {
219209
return $this->createErrors(
220210
$narrowedNativeType,

0 commit comments

Comments
 (0)