Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: phpstan/phpstan-src
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 75c4610ae0419d7051331fb34a621ccc8b7dad6a
Choose a base ref
..
head repository: phpstan/phpstan-src
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 224d41d9d852be07da592899cbbad033f1c368f3
Choose a head ref
Showing with 50 additions and 1 deletion.
  1. +9 −1 src/Type/VerbosityLevel.php
  2. +17 −0 tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php
  3. +24 −0 tests/PHPStan/Rules/PhpDoc/data/bug-12457.php
10 changes: 9 additions & 1 deletion src/Type/VerbosityLevel.php
Original file line number Diff line number Diff line change
@@ -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 (
17 changes: 17 additions & 0 deletions tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php
Original file line number Diff line number Diff line change
@@ -511,4 +511,21 @@ 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,
],
[
'PHPDoc tag @var with type callable(): string is not subtype of type callable(): numeric-string&lowercase-string&uppercase-string.',
22,
],
]);
}

}
24 changes: 24 additions & 0 deletions tests/PHPStan/Rules/PhpDoc/data/bug-12457.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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;
}

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