1717use PHPStan \Analyser \Scope ;
1818use PHPStan \Reflection \ExtendedMethodReflection ;
1919use PHPStan \Reflection \ParametersAcceptorSelector ;
20- use PHPStan \Type \ArrayType ;
21- use PHPStan \Type \BooleanType ;
22- use PHPStan \Type \ClassStringType ;
2320use PHPStan \Type \ClosureType ;
24- use PHPStan \Type \Enum \EnumCaseObjectType ;
2521use PHPStan \Type \IntegerRangeType ;
2622use PHPStan \Type \IntersectionType ;
2723use PHPStan \Type \MixedType ;
3531
3632final readonly class CollectorMetadataPrinter
3733{
38- private Standard $ printerStandard ;
34+ private Standard $ standard ;
3935
40- public function __construct ()
41- {
42- $ this ->printerStandard = new Standard ();
36+ public function __construct (
37+ ) {
38+ $ this ->standard = new Standard ();
4339 }
4440
4541 public function printArgTypesAsString (MethodCall $ methodCall , ExtendedMethodReflection $ extendedMethodReflection , Scope $ scope ): string
@@ -100,7 +96,7 @@ public function printParamTypesToString(ClassMethod $classMethod, ?string $class
10096 $ paramType = $ this ->resolveSortedTypes ($ paramType , $ className );
10197 }
10298
103- $ printedParamType = $ this ->printerStandard ->prettyPrint ([$ paramType ]);
99+ $ printedParamType = $ this ->standard ->prettyPrint ([$ paramType ]);
104100 $ printedParamType = str_replace ('\Closure ' , 'callable ' , $ printedParamType );
105101 $ printedParamType = ltrim ($ printedParamType , '\\' );
106102 $ printedParamType = str_replace ('| \\' , '| ' , $ printedParamType );
@@ -160,15 +156,15 @@ private function resolveSortedTypes(UnionType|NodeIntersectionType $paramType, ?
160156
161157 private function printTypeToString (Type $ type ): string
162158 {
163- if ($ type instanceof ClassStringType ) {
159+ if ($ type-> isClassString ()-> yes () ) {
164160 return 'string ' ;
165161 }
166162
167- if ($ type instanceof ArrayType ) {
163+ if ($ type-> isArray ()-> yes () ) {
168164 return 'array ' ;
169165 }
170166
171- if ($ type instanceof BooleanType ) {
167+ if ($ type-> isBoolean ()-> yes () ) {
172168 return 'bool ' ;
173169 }
174170
@@ -180,8 +176,8 @@ private function printTypeToString(Type $type): string
180176 return 'callable ' ;
181177 }
182178
183- if ($ type instanceof EnumCaseObjectType ) {
184- return $ type ->getClassName ();
179+ if (count ( $ type-> getEnumCases ()) === 1 ) {
180+ return $ type ->getEnumCases ()[ 0 ]-> getClassName ();
185181 }
186182
187183 return $ type ->describe (VerbosityLevel::typeOnly ());
0 commit comments