Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Type/Constant/ConstantStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function getObjectTypeOrClassStringObjectType(): Type
public function describe(VerbosityLevel $level): string
{
return $level->handle(
static fn (): string => 'string',
fn (): string => $this->isClassString ? 'class-string<' . $this->value . '>' : 'string',
function (): string {
$value = $this->value;

Expand Down
22 changes: 11 additions & 11 deletions tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ public function testBug4413(): void
require_once __DIR__ . '/data/bug-4413.php';
$this->analyse([__DIR__ . '/data/bug-4413.php'], [
[
'Parameter #1 $date of function Bug4413\takesDate expects class-string<DateTime>, string given.',
'Parameter #1 $date of function Bug4413\takesDate expects class-string<DateTime>, class-string<stdClass> given.',
18,
],
]);
Expand Down Expand Up @@ -1200,11 +1200,11 @@ public function testBug4371(): void
{
$errors = [
[
'Parameter #1 $object_or_class of function is_a expects object, string given.',
'Parameter #1 $object_or_class of function is_a expects object, class-string<Bug4371\Bar> given.',
14,
],
[
'Parameter #1 $object_or_class of function is_a expects object, string given.',
'Parameter #1 $object_or_class of function is_a expects object, class-string<Bug4371\Bar> given.',
22,
],
];
Expand All @@ -1213,11 +1213,11 @@ public function testBug4371(): void
// php 7.x had different parameter names
$errors = [
[
'Parameter #1 $object_or_string of function is_a expects object, string given.',
'Parameter #1 $object_or_string of function is_a expects object, class-string<Bug4371\Bar> given.',
14,
],
[
'Parameter #1 $object_or_string of function is_a expects object, string given.',
'Parameter #1 $object_or_string of function is_a expects object, class-string<Bug4371\Bar> given.',
22,
],
];
Expand All @@ -1230,15 +1230,15 @@ public function testIsSubclassAllowString(): void
{
$errors = [
[
'Parameter #1 $object_or_class of function is_subclass_of expects object, string given.',
'Parameter #1 $object_or_class of function is_subclass_of expects object, class-string<IsSubclassAllowString\A> given.',
11,
],
[
'Parameter #1 $object_or_class of function is_subclass_of expects object, string given.',
'Parameter #1 $object_or_class of function is_subclass_of expects object, class-string<IsSubclassAllowString\B> given.',
14,
],
[
'Parameter #1 $object_or_class of function is_subclass_of expects object, string given.',
'Parameter #1 $object_or_class of function is_subclass_of expects object, class-string<IsSubclassAllowString\B> given.',
17,
],
];
Expand All @@ -1247,15 +1247,15 @@ public function testIsSubclassAllowString(): void
// php 7.x had different parameter names
$errors = [
[
'Parameter #1 $object_or_string of function is_subclass_of expects object, string given.',
'Parameter #1 $object_or_string of function is_subclass_of expects object, class-string<IsSubclassAllowString\A> given.',
11,
],
[
'Parameter #1 $object_or_string of function is_subclass_of expects object, string given.',
'Parameter #1 $object_or_string of function is_subclass_of expects object, class-string<IsSubclassAllowString\B> given.',
14,
],
[
'Parameter #1 $object_or_string of function is_subclass_of expects object, string given.',
'Parameter #1 $object_or_string of function is_subclass_of expects object, class-string<IsSubclassAllowString\B> given.',
17,
],
];
Expand Down
4 changes: 2 additions & 2 deletions tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ public function testCallMethods(): void
1461,
],
[
'Parameter #1 $s of method Test\ClassStringWithUpperBounds::doFoo() expects class-string<Exception>, string given.',
'Parameter #1 $s of method Test\ClassStringWithUpperBounds::doFoo() expects class-string<Exception>, class-string<Throwable> given.',
1490,
],
[
Expand Down Expand Up @@ -834,7 +834,7 @@ public function testCallMethodsOnThisOnly(): void
1379,
],
[
'Parameter #1 $s of method Test\ClassStringWithUpperBounds::doFoo() expects class-string<Exception>, string given.',
'Parameter #1 $s of method Test\ClassStringWithUpperBounds::doFoo() expects class-string<Exception>, class-string<Throwable> given.',
1490,
],
[
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ public function testTemplateTypeInOneBranchOfConditional(): void
[
'Parameter #1 $params of static method TemplateTypeInOneBranchOfConditional\DriverManager::getConnection() expects array{wrapperClass?: class-string<TemplateTypeInOneBranchOfConditional\Connection>}, array{wrapperClass: \'stdClass\'} given.',
27,
"Offset 'wrapperClass' (class-string<TemplateTypeInOneBranchOfConditional\Connection>) does not accept type string.",
"Offset 'wrapperClass' (class-string<TemplateTypeInOneBranchOfConditional\Connection>) does not accept type class-string<stdClass>.",
],
[
'Unable to resolve the template type T in call to static method TemplateTypeInOneBranchOfConditional\DriverManager::getConnection()',
Expand Down
16 changes: 15 additions & 1 deletion tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ public function testBug8071(): void
// there should be no errors
'Method Bug8071\Inheritance::inherit() should return array<TKey of (int|string), TValues of bool|float|int|string|null> but returns array<string>.',
17,
'Type string is not always the same as TValues. It breaks the contract for some argument types, typically subtypes.',
"• Type class-string<Bug8071\Inheritance> is not always the same as TValues. It breaks the contract for some argument types, typically subtypes.\n• Type string is not always the same as TValues. It breaks the contract for some argument types, typically subtypes.",
],
]);
}
Expand Down Expand Up @@ -1331,4 +1331,18 @@ public function testBug11430(): void
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-11430.php'], []);
}

public function testBug14440(): void
{
$this->analyse([__DIR__ . '/data/bug-14440.php'], [
[
'Method Bug14440\ChildOne::getCounterpartClass() should return class-string<Bug14440\ChildOne> but returns class-string<Bug14440\ChildTwo>.',
18,
],
[
'Method Bug14440\ChildTwo::getCounterpartClass() should return class-string<Bug14440\ChildTwo> but returns class-string<Bug14440\ChildOne>.',
27,
],
]);
}

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

namespace Bug14440;

interface I {}

abstract class A
{
/** @return class-string<static&I> */
abstract public static function getCounterpartClass(): string;
}

final class ChildOne extends A implements I
{
#[\Override]
public static function getCounterpartClass(): string
{
return ChildTwo::class;
}
}

final class ChildTwo extends A implements I
{
#[\Override]
public static function getCounterpartClass(): string
{
return ChildOne::class;
}
}
Loading