Skip to content

Commit 91dc935

Browse files
committed
More verbose type descriptions in case of numeric-string
1 parent a74a300 commit 91dc935

4 files changed

Lines changed: 44 additions & 1 deletion

File tree

src/Type/IntersectionType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PHPStan\Reflection\TrivialParametersAcceptor;
1010
use PHPStan\Reflection\Type\IntersectionTypeMethodReflection;
1111
use PHPStan\TrinaryLogic;
12+
use PHPStan\Type\Accessory\AccessoryNumericStringType;
1213
use PHPStan\Type\Accessory\AccessoryType;
1314
use PHPStan\Type\Generic\TemplateTypeMap;
1415
use PHPStan\Type\Generic\TemplateTypeVariance;
@@ -132,7 +133,7 @@ function () use ($level): string {
132133
function () use ($level): string {
133134
$typeNames = [];
134135
foreach ($this->types as $type) {
135-
if ($type instanceof AccessoryType) {
136+
if ($type instanceof AccessoryType && !$type instanceof AccessoryNumericStringType) {
136137
continue;
137138
}
138139
$typeNames[] = $type->describe($level);

src/Type/VerbosityLevel.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace PHPStan\Type;
44

5+
use PHPStan\Type\Accessory\AccessoryNumericStringType;
6+
57
class VerbosityLevel
68
{
79

@@ -58,6 +60,10 @@ public static function getRecommendedLevelByType(Type $type): self
5860
$moreVerbose = true;
5961
return $type;
6062
}
63+
if ($type instanceof AccessoryNumericStringType) {
64+
$moreVerbose = true;
65+
return $type;
66+
}
6167
return $traverse($type);
6268
});
6369

tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ public function testCallMethods(): void
467467
'Parameter #1 $members of method Test\ParameterTypeCheckVerbosity::doBar() expects array<array(\'id\' => string, \'code\' => string)>, array<array(\'code\' => string)> given.',
468468
1589,
469469
],
470+
[
471+
'Parameter #1 $test of method Test\NumericStringParam::sayHello() expects string&numeric, 123 given.',
472+
1657,
473+
],
474+
[
475+
'Parameter #1 $test of method Test\NumericStringParam::sayHello() expects string&numeric, \'abc\' given.',
476+
1658,
477+
],
470478
]);
471479
}
472480

@@ -728,6 +736,14 @@ public function testCallMethodsOnThisOnly(): void
728736
'Parameter #1 $members of method Test\ParameterTypeCheckVerbosity::doBar() expects array<array(\'id\' => string, \'code\' => string)>, array<array(\'code\' => string)> given.',
729737
1589,
730738
],
739+
[
740+
'Parameter #1 $test of method Test\NumericStringParam::sayHello() expects string&numeric, 123 given.',
741+
1657,
742+
],
743+
[
744+
'Parameter #1 $test of method Test\NumericStringParam::sayHello() expects string&numeric, \'abc\' given.',
745+
1658,
746+
],
731747
]);
732748
}
733749

tests/PHPStan/Rules/Methods/data/call-methods.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,3 +1640,23 @@ public function doFoo(array $params)
16401640
}
16411641

16421642
}
1643+
1644+
class NumericStringParam
1645+
{
1646+
1647+
/**
1648+
* @param numeric-string $test
1649+
*/
1650+
public function sayHello(string $test): void
1651+
{
1652+
1653+
}
1654+
1655+
public function doFoo()
1656+
{
1657+
$this->sayHello(123);
1658+
$this->sayHello('abc');
1659+
$this->sayHello('123');
1660+
}
1661+
1662+
}

0 commit comments

Comments
 (0)