@@ -47,7 +47,7 @@ public function __construct(
4747 ) {
4848 }
4949
50- public function stringify (mixed $ raw , int $ depth ): ? string
50+ public function stringify (mixed $ raw , int $ depth ): string | null
5151 {
5252 if (!is_callable ($ raw )) {
5353 return null ;
@@ -69,15 +69,18 @@ public function stringify(mixed $raw, int $depth): ?string
6969 return $ this ->buildStaticMethod (new ReflectionMethod ($ raw [0 ], $ raw [1 ]), $ depth );
7070 }
7171
72- /** @var callable-string $raw */
73- if (str_contains ($ raw , ': ' )) {
72+ if (is_string ($ raw ) && str_contains ($ raw , ': ' )) {
7473 /** @var class-string $class */
7574 $ class = (string ) strstr ($ raw , ': ' , true );
7675 $ method = substr ((string ) strrchr ($ raw , ': ' ), 1 );
7776
7877 return $ this ->buildStaticMethod (new ReflectionMethod ($ class , $ method ), $ depth );
7978 }
8079
80+ if (!is_string ($ raw )) {
81+ return null ;
82+ }
83+
8184 return $ this ->buildFunction (new ReflectionFunction ($ raw ), $ depth );
8285 }
8386
@@ -90,15 +93,15 @@ private function buildMethod(ReflectionMethod $reflection, object $object, int $
9093 {
9194 return $ this ->quoter ->quote (
9295 sprintf ('%s->%s ' , $ this ->getName ($ object ), $ this ->buildSignature ($ reflection , $ depth )),
93- $ depth
96+ $ depth,
9497 );
9598 }
9699
97100 private function buildStaticMethod (ReflectionMethod $ reflection , int $ depth ): string
98101 {
99102 return $ this ->quoter ->quote (
100103 sprintf ('%s::%s ' , $ reflection ->class , $ this ->buildSignature ($ reflection , $ depth )),
101- $ depth
104+ $ depth,
102105 );
103106 }
104107
@@ -112,10 +115,10 @@ private function buildSignature(ReflectionFunctionAbstract $function, int $depth
112115 array_map (
113116 fn (ReflectionParameter $ parameter ): string => $ this ->buildParameter (
114117 $ parameter ,
115- $ depth + 1
118+ $ depth + 1 ,
116119 ),
117- $ function ->getParameters ()
118- )
120+ $ function ->getParameters (),
121+ ),
119122 ),
120123 );
121124
@@ -125,7 +128,7 @@ private function buildSignature(ReflectionFunctionAbstract $function, int $depth
125128 ' use ($%s) ' ,
126129 implode (
127130 ', $ ' ,
128- array_keys ($ closureUsedVariables )
131+ array_keys ($ closureUsedVariables ),
129132 ),
130133 );
131134 }
@@ -160,7 +163,7 @@ private function buildParameter(ReflectionParameter $reflectionParameter, int $d
160163 return $ parameter ;
161164 }
162165
163- private function buildValue (ReflectionParameter $ reflectionParameter , int $ depth ): ? string
166+ private function buildValue (ReflectionParameter $ reflectionParameter , int $ depth ): string | null
164167 {
165168 if (!$ reflectionParameter ->isDefaultValueAvailable ()) {
166169 return $ this ->stringifier ->stringify (null , $ depth );
@@ -178,19 +181,26 @@ private function buildType(ReflectionType $raw, int $depth): string
178181 if ($ raw instanceof ReflectionUnionType) {
179182 return implode (
180183 '| ' ,
181- array_map (fn (ReflectionType $ type ) => $ this ->buildType ($ type , $ depth ), $ raw ->getTypes ())
184+ array_map (fn (ReflectionType $ type ) => $ this ->buildType ($ type , $ depth ), $ raw ->getTypes ()),
182185 );
183186 }
184187
185188 if ($ raw instanceof ReflectionIntersectionType) {
186189 return implode (
187190 '& ' ,
188- array_map (fn (ReflectionType $ type ) => $ this ->buildType ($ type , $ depth ), $ raw ->getTypes ())
191+ array_map (fn (ReflectionType $ type ) => $ this ->buildType ($ type , $ depth ), $ raw ->getTypes ()),
189192 );
190193 }
191194
192- /** @var ReflectionNamedType $raw */
195+ if ($ raw instanceof ReflectionNamedType) {
196+ $ type = $ raw ->getName ();
197+ if ($ raw ->allowsNull ()) {
198+ $ type = sprintf ('?%s ' , $ type );
199+ }
200+
201+ return $ type ;
202+ }
193203
194- return ( $ raw -> allowsNull () ? ' ? ' : '' ) . $ raw -> getName () ;
204+ return '' ;
195205 }
196206}
0 commit comments