Skip to content

Commit 2f49187

Browse files
committed
ConditionalReturnTypeRuleHelper - increase type description verbosity
1 parent 3fa575f commit 2f49187

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/Rules/PhpDoc/ConditionalReturnTypeRuleHelper.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ public function check(ParametersAcceptor $acceptor): array
6161
continue;
6262
}
6363

64+
$verbosity = VerbosityLevel::getRecommendedLevelByType($subjectType, $targetType);
65+
6466
$errors[] = RuleErrorBuilder::message(sprintf(
6567
'Condition "%s" in conditional return type is always %s.',
66-
sprintf('%s %s %s', $subjectType->describe(VerbosityLevel::typeOnly()), $conditionalType->isNegated() ? 'is not' : 'is', $targetType->describe(VerbosityLevel::typeOnly())),
68+
sprintf('%s %s %s', $subjectType->describe($verbosity), $conditionalType->isNegated() ? 'is not' : 'is', $targetType->describe($verbosity)),
6769
$conditionalType->isNegated()
6870
? ($isTargetSuperType->yes() ? 'false' : 'true')
6971
: ($isTargetSuperType->yes() ? 'true' : 'false'),

tests/PHPStan/Rules/PhpDoc/MethodConditionalReturnTypeRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public function testRule(): void
6363
'Condition "int is not string" in conditional return type is always true.',
6464
142,
6565
],
66+
[
67+
'Condition "array{foo: string} is array{foo: int}" in conditional return type is always false.',
68+
156,
69+
],
6670
]);
6771
}
6872

tests/PHPStan/Rules/PhpDoc/data/method-conditional-return-type.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,17 @@ public function fill4(int $i): array
145145
}
146146

147147
}
148+
149+
class MoreVerboseDescription
150+
{
151+
152+
/**
153+
* @param array{foo: string} $i
154+
* @return ($i is array{foo: int} ? non-empty-array : array)
155+
*/
156+
public function fill(array $i): array
157+
{
158+
159+
}
160+
161+
}

0 commit comments

Comments
 (0)