Skip to content

Commit 12d855b

Browse files
phpstan-botclaude
andcommitted
Narrow verbosity escalation to only apply when both types contain TemplateType
The identical-description check was overly broad — it would escalate verbosity for any two types with the same description. Restrict it to only trigger when both the accepting and accepted types contain TemplateType, which is the actual scenario where different-scope templates produce confusingly identical descriptions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent dfae0ee commit 12d855b

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/Type/VerbosityLevel.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public static function getRecommendedLevelByType(Type $acceptingType, ?Type $acc
223223
if (!$containsInvariantTemplateType) {
224224
$level = $verbosity ?? self::typeOnly();
225225

226-
if ($acceptingType->describe($level) === $acceptedType->describe($level)) {
226+
if (self::containsTemplateType($acceptingType) && self::containsTemplateType($acceptedType) && $acceptingType->describe($level) === $acceptedType->describe($level)) {
227227
return self::precise();
228228
}
229229

@@ -242,13 +242,32 @@ public static function getRecommendedLevelByType(Type $acceptingType, ?Type $acc
242242

243243
$level = $moreVerbose ? self::value() : $verbosity ?? self::typeOnly();
244244

245-
if ($acceptingType->describe($level) === $acceptedType->describe($level)) {
245+
if (self::containsTemplateType($acceptingType) && self::containsTemplateType($acceptedType) && $acceptingType->describe($level) === $acceptedType->describe($level)) {
246246
return self::precise();
247247
}
248248

249249
return $level;
250250
}
251251

252+
private static function containsTemplateType(Type $type): bool
253+
{
254+
$found = false;
255+
TypeTraverser::map($type, static function (Type $type, callable $traverse) use (&$found): Type {
256+
if ($found) {
257+
return $type;
258+
}
259+
260+
if ($type instanceof TemplateType) {
261+
$found = true;
262+
return $type;
263+
}
264+
265+
return $traverse($type);
266+
});
267+
268+
return $found;
269+
}
270+
252271
/**
253272
* @param callable(): string $typeOnlyCallback
254273
* @param callable(): string $valueCallback

0 commit comments

Comments
 (0)