Skip to content

Commit 4c7046e

Browse files
committed
Type::getObjectClassReflections()
1 parent 93113cb commit 4c7046e

33 files changed

+172
-9
lines changed

Diff for: phpstan-baseline.neon

+4-4
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ parameters:
484484
path: src/Rules/Comparison/ImpossibleCheckTypeHelper.php
485485

486486
-
487-
message: "#^Doing instanceof PHPStan\\\\Type\\\\TypeWithClassName is error\\-prone and deprecated\\. Use Type\\:\\:getObjectClassNames\\(\\) instead\\.$#"
487+
message: "#^Doing instanceof PHPStan\\\\Type\\\\TypeWithClassName is error\\-prone and deprecated\\. Use Type\\:\\:getObjectClassNames\\(\\) or Type\\:\\:getObjectClassReflections\\(\\) instead\\.$#"
488488
count: 1
489489
path: src/Rules/Comparison/ImpossibleCheckTypeHelper.php
490490

@@ -904,7 +904,7 @@ parameters:
904904
path: src/Type/Generic/GenericObjectType.php
905905

906906
-
907-
message: "#^Doing instanceof PHPStan\\\\Type\\\\TypeWithClassName is error\\-prone and deprecated\\. Use Type\\:\\:getObjectClassNames\\(\\) instead\\.$#"
907+
message: "#^Doing instanceof PHPStan\\\\Type\\\\TypeWithClassName is error\\-prone and deprecated\\. Use Type\\:\\:getObjectClassNames\\(\\) or Type\\:\\:getObjectClassReflections\\(\\) instead\\.$#"
908908
count: 1
909909
path: src/Type/Generic/GenericObjectType.php
910910

@@ -1210,7 +1210,7 @@ parameters:
12101210
path: src/Type/Php/DefinedConstantTypeSpecifyingExtension.php
12111211

12121212
-
1213-
message: "#^Doing instanceof PHPStan\\\\Type\\\\TypeWithClassName is error\\-prone and deprecated\\. Use Type\\:\\:getObjectClassNames\\(\\) instead\\.$#"
1213+
message: "#^Doing instanceof PHPStan\\\\Type\\\\TypeWithClassName is error\\-prone and deprecated\\. Use Type\\:\\:getObjectClassNames\\(\\) or Type\\:\\:getObjectClassReflections\\(\\) instead\\.$#"
12141214
count: 1
12151215
path: src/Type/Php/DsMapDynamicReturnTypeExtension.php
12161216

@@ -1423,7 +1423,7 @@ parameters:
14231423
path: src/Type/TypeUtils.php
14241424

14251425
-
1426-
message: "#^Doing instanceof PHPStan\\\\Type\\\\TypeWithClassName is error\\-prone and deprecated\\. Use Type\\:\\:getObjectClassNames\\(\\) instead\\.$#"
1426+
message: "#^Doing instanceof PHPStan\\\\Type\\\\TypeWithClassName is error\\-prone and deprecated\\. Use Type\\:\\:getObjectClassNames\\(\\) or Type\\:\\:getObjectClassReflections\\(\\) instead\\.$#"
14271427
count: 1
14281428
path: src/Type/TypeUtils.php
14291429

Diff for: src/Rules/Api/ApiInstanceofTypeRule.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ApiInstanceofTypeRule implements Rule
5151
{
5252

5353
private const MAP = [
54-
TypeWithClassName::class => 'Type::getObjectClassNames()',
54+
TypeWithClassName::class => 'Type::getObjectClassNames() or Type::getObjectClassReflections()',
5555
EnumCaseObjectType::class => 'Type::getEnumCases()',
5656
ConstantArrayType::class => 'Type::getConstantArrays()',
5757
ArrayType::class => 'Type::isArray() or Type::getArrays()',

Diff for: src/Type/Accessory/AccessoryArrayListType.php

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public function getObjectClassNames(): array
5454
return [];
5555
}
5656

57+
public function getObjectClassReflections(): array
58+
{
59+
return [];
60+
}
61+
5762
public function getArrays(): array
5863
{
5964
return [];

Diff for: src/Type/Accessory/AccessoryLiteralStringType.php

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public function getObjectClassNames(): array
5555
return [];
5656
}
5757

58+
public function getObjectClassReflections(): array
59+
{
60+
return [];
61+
}
62+
5863
public function getConstantStrings(): array
5964
{
6065
return [];

Diff for: src/Type/Accessory/AccessoryNonEmptyStringType.php

+5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public function getObjectClassNames(): array
5656
return [];
5757
}
5858

59+
public function getObjectClassReflections(): array
60+
{
61+
return [];
62+
}
63+
5964
public function getConstantStrings(): array
6065
{
6166
return [];

Diff for: src/Type/Accessory/AccessoryNonFalsyStringType.php

+5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public function getObjectClassNames(): array
5757
return [];
5858
}
5959

60+
public function getObjectClassReflections(): array
61+
{
62+
return [];
63+
}
64+
6065
public function getConstantStrings(): array
6166
{
6267
return [];

Diff for: src/Type/Accessory/AccessoryNumericStringType.php

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public function getObjectClassNames(): array
5555
return [];
5656
}
5757

58+
public function getObjectClassReflections(): array
59+
{
60+
return [];
61+
}
62+
5863
public function getConstantStrings(): array
5964
{
6065
return [];

Diff for: src/Type/Accessory/HasMethodType.php

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public function getObjectClassNames(): array
4949
return [];
5050
}
5151

52+
public function getObjectClassReflections(): array
53+
{
54+
return [];
55+
}
56+
5257
private function getCanonicalMethodName(): string
5358
{
5459
return strtolower($this->methodName);

Diff for: src/Type/Accessory/HasOffsetType.php

+5
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ public function getObjectClassNames(): array
6767
return [];
6868
}
6969

70+
public function getObjectClassReflections(): array
71+
{
72+
return [];
73+
}
74+
7075
public function getConstantStrings(): array
7176
{
7277
return [];

Diff for: src/Type/Accessory/HasOffsetValueType.php

+5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ public function getObjectClassNames(): array
6666
return [];
6767
}
6868

69+
public function getObjectClassReflections(): array
70+
{
71+
return [];
72+
}
73+
6974
public function getConstantStrings(): array
7075
{
7176
return [];

Diff for: src/Type/Accessory/HasPropertyType.php

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public function getObjectClassNames(): array
4646
return [];
4747
}
4848

49+
public function getObjectClassReflections(): array
50+
{
51+
return [];
52+
}
53+
4954
public function getConstantStrings(): array
5055
{
5156
return [];

Diff for: src/Type/Accessory/NonEmptyArrayType.php

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public function getObjectClassNames(): array
5151
return [];
5252
}
5353

54+
public function getObjectClassReflections(): array
55+
{
56+
return [];
57+
}
58+
5459
public function getArrays(): array
5560
{
5661
return [];

Diff for: src/Type/Accessory/OversizedArrayType.php

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public function getObjectClassNames(): array
4949
return [];
5050
}
5151

52+
public function getObjectClassReflections(): array
53+
{
54+
return [];
55+
}
56+
5257
public function getArrays(): array
5358
{
5459
return [];

Diff for: src/Type/ArrayType.php

+5
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public function getObjectClassNames(): array
7777
return [];
7878
}
7979

80+
public function getObjectClassReflections(): array
81+
{
82+
return [];
83+
}
84+
8085
public function getArrays(): array
8186
{
8287
return [$this];

Diff for: src/Type/CallableType.php

+5
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ public function getObjectClassNames(): array
8080
return [];
8181
}
8282

83+
public function getObjectClassReflections(): array
84+
{
85+
return [];
86+
}
87+
8388
public function getConstantStrings(): array
8489
{
8590
return [];

Diff for: src/Type/ClosureType.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ public function getReferencedClasses(): array
100100

101101
public function getObjectClassNames(): array
102102
{
103-
return [$this->objectType->getClassName()];
103+
return $this->objectType->getObjectClassNames();
104+
}
105+
106+
public function getObjectClassReflections(): array
107+
{
108+
return $this->objectType->getObjectClassReflections();
104109
}
105110

106111
public function accepts(Type $type, bool $strictTypes): TrinaryLogic

Diff for: src/Type/FloatType.php

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ public function getObjectClassNames(): array
5252
return [];
5353
}
5454

55+
public function getObjectClassReflections(): array
56+
{
57+
return [];
58+
}
59+
5560
public function getConstantStrings(): array
5661
{
5762
return [];

Diff for: src/Type/IntersectionType.php

+12
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ public function getObjectClassNames(): array
122122
return array_values(array_unique($objectClassNames));
123123
}
124124

125+
public function getObjectClassReflections(): array
126+
{
127+
$reflections = [];
128+
foreach ($this->types as $type) {
129+
foreach ($type->getObjectClassReflections() as $reflection) {
130+
$reflections[] = $reflection;
131+
}
132+
}
133+
134+
return $reflections;
135+
}
136+
125137
public function getArrays(): array
126138
{
127139
$arrays = [];

Diff for: src/Type/IterableType.php

+5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ public function getObjectClassNames(): array
6666
return [];
6767
}
6868

69+
public function getObjectClassReflections(): array
70+
{
71+
return [];
72+
}
73+
6974
public function getConstantStrings(): array
7075
{
7176
return [];

Diff for: src/Type/JustNullableTypeTrait.php

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public function getObjectClassNames(): array
2121
return [];
2222
}
2323

24+
public function getObjectClassReflections(): array
25+
{
26+
return [];
27+
}
28+
2429
public function accepts(Type $type, bool $strictTypes): TrinaryLogic
2530
{
2631
return $this->acceptsWithReason($type, $strictTypes)->result;

Diff for: src/Type/MixedType.php

+5
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ public function getObjectClassNames(): array
6969
return [];
7070
}
7171

72+
public function getObjectClassReflections(): array
73+
{
74+
return [];
75+
}
76+
7277
public function getArrays(): array
7378
{
7479
return [];

Diff for: src/Type/NeverType.php

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public function getObjectClassNames(): array
6262
return [];
6363
}
6464

65+
public function getObjectClassReflections(): array
66+
{
67+
return [];
68+
}
69+
6570
public function getConstantStrings(): array
6671
{
6772
return [];

Diff for: src/Type/NullType.php

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public function getObjectClassNames(): array
4747
return [];
4848
}
4949

50+
public function getObjectClassReflections(): array
51+
{
52+
return [];
53+
}
54+
5055
public function getConstantStrings(): array
5156
{
5257
return [];

Diff for: src/Type/ObjectType.php

+10
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,16 @@ public function getObjectClassNames(): array
236236
return [$this->className];
237237
}
238238

239+
public function getObjectClassReflections(): array
240+
{
241+
$classReflection = $this->getClassReflection();
242+
if ($classReflection === null) {
243+
return [];
244+
}
245+
246+
return [$classReflection];
247+
}
248+
239249
public function accepts(Type $type, bool $strictTypes): TrinaryLogic
240250
{
241251
return $this->acceptsWithReason($type, $strictTypes)->result;

Diff for: src/Type/ObjectWithoutClassType.php

+5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public function getObjectClassNames(): array
4545
return [];
4646
}
4747

48+
public function getObjectClassReflections(): array
49+
{
50+
return [];
51+
}
52+
4853
public function accepts(Type $type, bool $strictTypes): TrinaryLogic
4954
{
5055
return $this->acceptsWithReason($type, $strictTypes)->result;

Diff for: src/Type/OffsetAccessType.php

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public function getObjectClassNames(): array
3535
return [];
3636
}
3737

38+
public function getObjectClassReflections(): array
39+
{
40+
return [];
41+
}
42+
3843
public function getReferencedTemplateTypes(TemplateTypeVariance $positionVariance): array
3944
{
4045
return array_merge(

Diff for: src/Type/StaticType.php

+5
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ public function getObjectClassNames(): array
109109
return $this->getStaticObjectType()->getObjectClassNames();
110110
}
111111

112+
public function getObjectClassReflections(): array
113+
{
114+
return $this->getStaticObjectType()->getObjectClassReflections();
115+
}
116+
112117
public function getArrays(): array
113118
{
114119
return $this->getStaticObjectType()->getArrays();

Diff for: src/Type/StrictMixedType.php

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public function getObjectClassNames(): array
3939
return [];
4040
}
4141

42+
public function getObjectClassReflections(): array
43+
{
44+
return [];
45+
}
46+
4247
public function getConstantStrings(): array
4348
{
4449
return [];

Diff for: src/Type/Traits/LateResolvableTypeTrait.php

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public function getObjectClassNames(): array
2828
return $this->resolve()->getObjectClassNames();
2929
}
3030

31+
public function getObjectClassReflections(): array
32+
{
33+
return $this->resolve()->getObjectClassReflections();
34+
}
35+
3136
public function getArrays(): array
3237
{
3338
return $this->resolve()->getArrays();

0 commit comments

Comments
 (0)