Skip to content

Commit dc330b4

Browse files
phpstan-botclaude
andcommitted
Move class-string verbosity logic to VerbosityLevel::getRecommendedLevelByType
Instead of modifying ConstantStringType::describe() at typeOnly level, use VerbosityLevel to bump to value level when the accepting type contains class-string types. The class-string<ClassName> description is now shown at value verbosity level instead of typeOnly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 01d608d commit dc330b4

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

src/Type/Constant/ConstantStringType.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,18 @@ public function getObjectTypeOrClassStringObjectType(): Type
113113
public function describe(VerbosityLevel $level): string
114114
{
115115
return $level->handle(
116-
fn (): string => $this->isClassString ? 'class-string<' . $this->value . '>' : 'string',
116+
static fn (): string => 'string',
117117
function (): string {
118+
if ($this->isClassString) {
119+
return 'class-string<' . $this->value . '>';
120+
}
121+
118122
$value = $this->value;
119123

120-
if (!$this->isClassString) {
121-
try {
122-
$value = Strings::truncate($value, self::DESCRIBE_LIMIT);
123-
} catch (RegexpException) {
124-
$value = substr($value, 0, self::DESCRIBE_LIMIT) . "\u{2026}";
125-
}
124+
try {
125+
$value = Strings::truncate($value, self::DESCRIBE_LIMIT);
126+
} catch (RegexpException) {
127+
$value = substr($value, 0, self::DESCRIBE_LIMIT) . "\u{2026}";
126128
}
127129

128130
return self::export($value);

src/Type/VerbosityLevel.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ public static function getRecommendedLevelByType(Type $acceptingType, ?Type $acc
174174
$moreVerbose = true;
175175
return $type;
176176
}
177+
if ($type->isClassString()->yes()) {
178+
$moreVerbose = true;
179+
return $type;
180+
}
177181
return $traverse($type);
178182
};
179183

0 commit comments

Comments
 (0)