Skip to content

Commit 5702d17

Browse files
Introduce new method
1 parent f04fd0c commit 5702d17

23 files changed

+108
-26
lines changed

src/Type/Accessory/HasMethodType.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPStan\Type\AcceptsResult;
1515
use PHPStan\Type\CompoundType;
1616
use PHPStan\Type\ErrorType;
17+
use PHPStan\Type\Generic\GenericClassStringType;
1718
use PHPStan\Type\IntersectionType;
1819
use PHPStan\Type\IsSuperTypeOfResult;
1920
use PHPStan\Type\StringType;
@@ -57,6 +58,11 @@ public function getObjectClassReflections(): array
5758
return [];
5859
}
5960

61+
public function getClassStringType(): Type
62+
{
63+
return new GenericClassStringType($this);
64+
}
65+
6066
private function getCanonicalMethodName(): string
6167
{
6268
return strtolower($this->methodName);

src/Type/Accessory/HasPropertyType.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PHPStan\Type\AcceptsResult;
1111
use PHPStan\Type\CompoundType;
1212
use PHPStan\Type\ErrorType;
13+
use PHPStan\Type\Generic\GenericClassStringType;
1314
use PHPStan\Type\IntersectionType;
1415
use PHPStan\Type\IsSuperTypeOfResult;
1516
use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
@@ -51,6 +52,11 @@ public function getObjectClassReflections(): array
5152
return [];
5253
}
5354

55+
public function getClassStringType(): Type
56+
{
57+
return new GenericClassStringType($this);
58+
}
59+
5460
public function getConstantStrings(): array
5561
{
5662
return [];

src/Type/ClosureType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,11 @@ public function isObject(): TrinaryLogic
295295
return $this->objectType->isObject();
296296
}
297297

298+
public function getClassStringType(): Type
299+
{
300+
return $this->objectType->getClassStringType();
301+
}
302+
298303
public function isEnum(): TrinaryLogic
299304
{
300305
return $this->objectType->isEnum();

src/Type/Enum/EnumCaseObjectType.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use PHPStan\Type\CompoundType;
1919
use PHPStan\Type\Constant\ConstantStringType;
2020
use PHPStan\Type\GeneralizePrecision;
21+
use PHPStan\Type\Generic\GenericClassStringType;
2122
use PHPStan\Type\IsSuperTypeOfResult;
2223
use PHPStan\Type\NeverType;
2324
use PHPStan\Type\ObjectType;
@@ -217,6 +218,11 @@ public function getEnumCases(): array
217218
return [$this];
218219
}
219220

221+
public function getClassStringType(): Type
222+
{
223+
return new GenericClassStringType(new ObjectType($this->getClassName()));
224+
}
225+
220226
public function toPhpDocNode(): TypeNode
221227
{
222228
return new ConstTypeNode(

src/Type/Generic/TemplateMixedType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,8 @@ public function toStrictMixedType(): TemplateStrictMixedType
6363
);
6464
}
6565

66+
public function getClassStringType(): Type
67+
{
68+
return new GenericClassStringType($this);
69+
}
6670
}

src/Type/Generic/TemplateObjectWithoutClassType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,9 @@ public function __construct(
3636
$this->default = $default;
3737
}
3838

39+
public function getClassStringType(): Type
40+
{
41+
return new GenericClassStringType($this);
42+
}
43+
3944
}

src/Type/IntersectionType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,11 @@ public function isObject(): TrinaryLogic
497497
return $this->intersectResults(static fn (Type $type): TrinaryLogic => $type->isObject());
498498
}
499499

500+
public function getClassStringType(): Type
501+
{
502+
return $this->intersectTypes(static fn (Type $type): Type => $type->getClassStringType());
503+
}
504+
500505
public function isEnum(): TrinaryLogic
501506
{
502507
return $this->intersectResults(static fn (Type $type): TrinaryLogic => $type->isEnum());

src/Type/MixedType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,11 @@ public function isObject(): TrinaryLogic
386386
return TrinaryLogic::createMaybe();
387387
}
388388

389+
public function getClassStringType(): Type
390+
{
391+
return new ClassStringType();
392+
}
393+
389394
public function isEnum(): TrinaryLogic
390395
{
391396
if ($this->subtractedType !== null) {

src/Type/NeverType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ public function isObject(): TrinaryLogic
113113
return TrinaryLogic::createNo();
114114
}
115115

116+
public function getClassStringType(): Type
117+
{
118+
return new NeverType();
119+
}
120+
116121
public function isEnum(): TrinaryLogic
117122
{
118123
return TrinaryLogic::createNo();

src/Type/NonexistentParentClassType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ public function isObject(): TrinaryLogic
5252
return TrinaryLogic::createYes();
5353
}
5454

55+
public function getClassStringType(): Type
56+
{
57+
return new ClassStringType();
58+
}
59+
5560
public function isEnum(): TrinaryLogic
5661
{
5762
return TrinaryLogic::createNo();

0 commit comments

Comments
 (0)