Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion src/Type/StaticType.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PHPStan\Reflection\Type\UnresolvedPropertyPrototypeReflection;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Enum\EnumCaseObjectType;
use PHPStan\Type\Generic\GenericClassStringType;
use PHPStan\Type\Generic\GenericObjectType;
use PHPStan\Type\Generic\TemplateTypeHelper;
use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
Expand Down Expand Up @@ -200,7 +201,7 @@ public function isObject(): TrinaryLogic

public function getClassStringType(): Type
{
return $this->getStaticObjectType()->getClassStringType();
return new GenericClassStringType($this);
}

public function isEnum(): TrinaryLogic
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/data/bug-7391b.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static function m() {
assertType('Bug7391B\Foo', (self::class)::m());
assertType('static(Bug7391B\Foo)', (static::class)::m());
assertType('Bug7391B\Foo', get_class(new self(2))::m());
assertType('Bug7391B\Foo', get_class(new static(2))::m());
assertType('static(Bug7391B\Foo)', get_class(new static(2))::m());

throw new \Error('For static analysis only, return type is resolved purely by DynamicStaticMethodReturnTypeExtension');
}
Expand Down
25 changes: 25 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-4860.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php declare(strict_types = 1);

namespace Bug4860;

use function PHPStan\Testing\assertType;

class Test
{
public function copy(): static
{
assertType('class-string<$this(Bug4860\Test)>', get_class($this));
return $this->copyTo(get_class($this));
}

/**
* @template T
* @param class-string<T> $targetEntity
* @return T
*/
public function copyTo(string $targetEntity)
{
/** @var T */
return new $targetEntity();
}
}
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/nsrt/get-parent-class.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function doFoo()
{
assertType('false', get_parent_class());
assertType('false', get_parent_class($this));
assertType('class-string<ParentClass\Foo>', get_class($this));
assertType('class-string<$this(ParentClass\Foo)>', get_class($this));
assertType('\'ParentClass\\\\Foo\'', get_class());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ public function testBug3633(): void
$tipText = 'Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.';
$this->analyse([__DIR__ . '/data/bug-3633.php'], [
[
'Strict comparison using === between class-string<Bug3633\HelloWorld> and \'Bug3633\\\OtherClass\' will always evaluate to false.',
'Strict comparison using === between class-string<$this(Bug3633\HelloWorld)> and \'Bug3633\\\OtherClass\' will always evaluate to false.',
37,
$tipText,
],
Expand All @@ -580,7 +580,7 @@ public function testBug3633(): void
44,
],
[
'Strict comparison using === between class-string<Bug3633\OtherClass> and \'Bug3633\\\HelloWorld\' will always evaluate to false.',
'Strict comparison using === between class-string<$this(Bug3633\OtherClass)> and \'Bug3633\\\HelloWorld\' will always evaluate to false.',
64,
$tipText,
],
Expand All @@ -595,12 +595,12 @@ public function testBug3633(): void
$tipText,
],
[
'Strict comparison using === between class-string<Bug3633\FinalClass> and \'Bug3633\\\HelloWorld\' will always evaluate to false.',
'Strict comparison using === between class-string<$this(Bug3633\FinalClass)> and \'Bug3633\\\HelloWorld\' will always evaluate to false.',
93,
$tipText,
],
[
'Strict comparison using === between class-string<Bug3633\FinalClass> and \'Bug3633\\\OtherClass\' will always evaluate to false.',
'Strict comparison using === between class-string<$this(Bug3633\FinalClass)> and \'Bug3633\\\OtherClass\' will always evaluate to false.',
96,
$tipText,
],
Expand Down
Loading