Skip to content

Commit

Permalink
Traverse typewhen we can contain lowercase/upercase strings
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Jan 21, 2025
1 parent d06f792 commit 36406a9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Type/VerbosityLevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,18 @@ public static function getRecommendedLevelByType(Type $acceptingType, ?Type $acc
$moreVerboseCallback = static function (Type $type, callable $traverse) use (&$moreVerbose, &$veryVerbose): Type {
if ($type->isCallable()->yes()) {
$moreVerbose = true;
return $type;

// Keep checking if we need to be very verbose.
return $traverse($type);
}
if ($type->isConstantValue()->yes() && $type->isNull()->no()) {
$moreVerbose = true;

// For ConstantArrayType we need to keep checking if we need to be very verbose.
if (!$type->isArray()->no()) {
return $traverse($type);
}

return $type;
}
if (
Expand Down
13 changes: 13 additions & 0 deletions tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,4 +511,17 @@ public function testReportWrongType(
$this->analyse([__DIR__ . '/data/wrong-var-native-type.php'], $expectedErrors);
}

public function testBug12457(): void
{
$this->checkTypeAgainstNativeType = true;
$this->checkTypeAgainstPhpDocType = true;
$this->strictWideningCheck = true;
$this->analyse([__DIR__ . '/data/bug-12457.php'], [
[
'PHPDoc tag @var with type array{numeric-string} is not subtype of type array{lowercase-string&numeric-string&uppercase-string}.',
13,
],
]);
}

}
15 changes: 15 additions & 0 deletions tests/PHPStan/Rules/PhpDoc/data/bug-12457.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php declare(strict_types = 1);

namespace Bug12457;

class HelloWorld
{
/**
* @param array{numeric-string&uppercase-string&lowercase-string} $a
*/
public function sayHello(array $a): void
{
/** @var array{numeric-string} $b */
$b = $a;
}
}

0 comments on commit 36406a9

Please sign in to comment.