Skip to content

Commit eac96db

Browse files
Introduce new method
1 parent b5097d7 commit eac96db

23 files changed

+107
-26
lines changed

src/Type/Accessory/HasMethodType.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPStan\Type\CompoundType;
1616
use PHPStan\Type\Enum\EnumCaseObjectType;
1717
use PHPStan\Type\ErrorType;
18+
use PHPStan\Type\Generic\GenericClassStringType;
1819
use PHPStan\Type\IntersectionType;
1920
use PHPStan\Type\IsSuperTypeOfResult;
2021
use PHPStan\Type\StringType;
@@ -58,6 +59,11 @@ public function getObjectClassReflections(): array
5859
return [];
5960
}
6061

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

src/Type/Accessory/HasPropertyType.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use PHPStan\Type\CompoundType;
1212
use PHPStan\Type\Enum\EnumCaseObjectType;
1313
use PHPStan\Type\ErrorType;
14+
use PHPStan\Type\Generic\GenericClassStringType;
1415
use PHPStan\Type\IntersectionType;
1516
use PHPStan\Type\IsSuperTypeOfResult;
1617
use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
@@ -52,6 +53,11 @@ public function getObjectClassReflections(): array
5253
return [];
5354
}
5455

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

src/Type/ClosureType.php

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

300+
public function getClassStringType(): Type
301+
{
302+
return $this->objectType->getClassStringType();
303+
}
304+
300305
public function isEnum(): TrinaryLogic
301306
{
302307
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;
@@ -222,6 +223,11 @@ public function getEnumCaseObject(): ?EnumCaseObjectType
222223
return $this;
223224
}
224225

226+
public function getClassStringType(): Type
227+
{
228+
return new GenericClassStringType(new ObjectType($this->getClassName()));
229+
}
230+
225231
public function toPhpDocNode(): TypeNode
226232
{
227233
return new ConstTypeNode(

src/Type/Generic/TemplateMixedType.php

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

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

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
@@ -520,6 +520,11 @@ public function isObject(): TrinaryLogic
520520
return $this->intersectResults(static fn (Type $type): TrinaryLogic => $type->isObject());
521521
}
522522

523+
public function getClassStringType(): Type
524+
{
525+
return $this->intersectTypes(static fn (Type $type): Type => $type->getClassStringType());
526+
}
527+
523528
public function isEnum(): TrinaryLogic
524529
{
525530
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
@@ -392,6 +392,11 @@ public function isObject(): TrinaryLogic
392392
return TrinaryLogic::createMaybe();
393393
}
394394

395+
public function getClassStringType(): Type
396+
{
397+
return new ClassStringType();
398+
}
399+
395400
public function isEnum(): TrinaryLogic
396401
{
397402
if ($this->subtractedType !== null) {

src/Type/NeverType.php

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

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

src/Type/NonexistentParentClassType.php

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

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

0 commit comments

Comments
 (0)