@@ -124,27 +124,42 @@ public function getReferencedClasses(): array
124
124
125
125
public function getObjectClassNames (): array
126
126
{
127
- return array_values (array_unique ($ this ->pickFromTypes (static fn (Type $ type ) => $ type ->getObjectClassNames ())));
127
+ return array_values (array_unique ($ this ->pickFromTypes (
128
+ static fn (Type $ type ) => $ type ->getObjectClassNames (),
129
+ static fn (Type $ type ) => $ type ->isObject ()->yes (),
130
+ )));
128
131
}
129
132
130
133
public function getObjectClassReflections (): array
131
134
{
132
- return $ this ->pickFromTypes (static fn (Type $ type ) => $ type ->getObjectClassReflections ());
135
+ return $ this ->pickFromTypes (
136
+ static fn (Type $ type ) => $ type ->getObjectClassReflections (),
137
+ static fn (Type $ type ) => $ type ->isObject ()->yes (),
138
+ );
133
139
}
134
140
135
141
public function getArrays (): array
136
142
{
137
- return $ this ->pickFromTypes (static fn (Type $ type ) => $ type ->getArrays ());
143
+ return $ this ->pickFromTypes (
144
+ static fn (Type $ type ) => $ type ->getArrays (),
145
+ static fn (Type $ type ) => $ type ->isArray ()->yes (),
146
+ );
138
147
}
139
148
140
149
public function getConstantArrays (): array
141
150
{
142
- return $ this ->pickFromTypes (static fn (Type $ type ) => $ type ->getConstantArrays ());
151
+ return $ this ->pickFromTypes (
152
+ static fn (Type $ type ) => $ type ->getConstantArrays (),
153
+ static fn (Type $ type ) => $ type ->isArray ()->yes (),
154
+ );
143
155
}
144
156
145
157
public function getConstantStrings (): array
146
158
{
147
- return $ this ->pickFromTypes (static fn (Type $ type ) => $ type ->getConstantStrings ());
159
+ return $ this ->pickFromTypes (
160
+ static fn (Type $ type ) => $ type ->getConstantStrings (),
161
+ static fn (Type $ type ) => $ type ->isString ()->yes (),
162
+ );
148
163
}
149
164
150
165
public function accepts (Type $ type , bool $ strictTypes ): TrinaryLogic
@@ -719,7 +734,10 @@ public function shuffleArray(): Type
719
734
720
735
public function getEnumCases (): array
721
736
{
722
- return $ this ->pickFromTypes (static fn (Type $ type ) => $ type ->getEnumCases ());
737
+ return $ this ->pickFromTypes (
738
+ static fn (Type $ type ) => $ type ->getEnumCases (),
739
+ static fn (Type $ type ) => $ type ->isObject ()->yes (),
740
+ );
723
741
}
724
742
725
743
public function isCallable (): TrinaryLogic
@@ -1073,15 +1091,19 @@ protected function unionTypes(callable $getType): Type
1073
1091
*/
1074
1092
protected function pickTypes (callable $ getTypes ): array
1075
1093
{
1076
- return $ this ->pickFromTypes ($ getTypes );
1094
+ return $ this ->pickFromTypes ($ getTypes, static fn () => false );
1077
1095
}
1078
1096
1079
1097
/**
1080
1098
* @template T
1081
1099
* @param callable(Type $type): list<T> $getValues
1100
+ * @param callable(Type $type): bool $criteria
1082
1101
* @return list<T>
1083
1102
*/
1084
- protected function pickFromTypes (callable $ getValues ): array
1103
+ protected function pickFromTypes (
1104
+ callable $ getValues ,
1105
+ callable $ criteria ,
1106
+ ): array
1085
1107
{
1086
1108
$ values = [];
1087
1109
foreach ($ this ->types as $ type ) {
0 commit comments