@@ -42,7 +42,7 @@ final class TypeResolver
4242 /** @var int the iterator parser is inside a collection expression context */
4343 const PARSER_IN_COLLECTION_EXPRESSION = 3 ;
4444
45- /** @var string[] List of recognized keywords and unto which Value Object they map */
45+ /** @var array< string, string> List of recognized keywords and unto which Value Object they map */
4646 private $ keywords = [
4747 'string ' => Types \String_::class,
4848 'int ' => Types \Integer::class,
@@ -133,7 +133,7 @@ public function resolve(string $type, Context $context = null): Type
133133 * the context where we are in the parsing
134134 * @return Type
135135 */
136- private function parseTypes (\ArrayIterator $ tokens , Context $ context , $ parserContext )
136+ private function parseTypes (\ArrayIterator $ tokens , Context $ context , $ parserContext ): Type
137137 {
138138 $ types = [];
139139 $ token = '' ;
@@ -257,7 +257,7 @@ private function parseTypes(\ArrayIterator $tokens, Context $context, $parserCon
257257 * @param string $type the type string, representing a single type
258258 * @return Type|Array_|Object_
259259 */
260- private function resolveSingleType ($ type , Context $ context )
260+ private function resolveSingleType (string $ type , Context $ context )
261261 {
262262 switch (true ) {
263263 case $ this ->isKeyword ($ type ):
@@ -281,11 +281,8 @@ private function resolveSingleType($type, Context $context)
281281
282282 /**
283283 * Adds a keyword to the list of Keywords and associates it with a specific Value Object.
284- *
285- * @param string $keyword
286- * @param string $typeClassName
287284 */
288- public function addKeyword ($ keyword , $ typeClassName )
285+ public function addKeyword (string $ keyword , string $ typeClassName ): void
289286 {
290287 if (!class_exists ($ typeClassName )) {
291288 throw new \InvalidArgumentException (
@@ -307,10 +304,8 @@ public function addKeyword($keyword, $typeClassName)
307304 * Detects whether the given type represents an array.
308305 *
309306 * @param string $type A relative or absolute type as defined in the phpDocumentor documentation.
310- *
311- * @return bool
312307 */
313- private function isTypedArray ($ type )
308+ private function isTypedArray (string $ type ): bool
314309 {
315310 return substr ($ type , -2 ) === self ::OPERATOR_ARRAY ;
316311 }
@@ -319,10 +314,8 @@ private function isTypedArray($type)
319314 * Detects whether the given type represents a PHPDoc keyword.
320315 *
321316 * @param string $type A relative or absolute type as defined in the phpDocumentor documentation.
322- *
323- * @return bool
324317 */
325- private function isKeyword ($ type )
318+ private function isKeyword (string $ type ): bool
326319 {
327320 return in_array (strtolower ($ type ), array_keys ($ this ->keywords ), true );
328321 }
@@ -334,45 +327,38 @@ private function isKeyword($type)
334327 *
335328 * @return bool
336329 */
337- private function isPartialStructuralElementName ($ type )
330+ private function isPartialStructuralElementName (string $ type ): bool
338331 {
339332 return ($ type [0 ] !== self ::OPERATOR_NAMESPACE ) && !$ this ->isKeyword ($ type );
340333 }
341334
342335 /**
343336 * Tests whether the given type is a Fully Qualified Structural Element Name.
344- *
345- * @param string $type
346- *
347- * @return bool
348337 */
349- private function isFqsen ($ type )
338+ private function isFqsen (string $ type ): bool
350339 {
351340 return strpos ($ type , self ::OPERATOR_NAMESPACE ) === 0 ;
352341 }
353342
354343 /**
355344 * Resolves the given typed array string (i.e. `string[]`) into an Array object with the right types set.
356- *
357- * @param string $type
358- * @return Array_
359345 */
360- private function resolveTypedArray ($ type , Context $ context )
346+ private function resolveTypedArray (string $ type , Context $ context ): Array_
361347 {
362348 return new Array_ ($ this ->resolveSingleType (substr ($ type , 0 , -2 ), $ context ));
363349 }
364350
365351 /**
366352 * Resolves the given keyword (such as `string`) into a Type object representing that keyword.
367- *
368- * @param string $type
369- *
370- * @return Type
353+ * @psalm-suppress MoreSpecificReturnType
371354 */
372- private function resolveKeyword ($ type )
355+ private function resolveKeyword (string $ type ): Type
373356 {
374357 $ className = $ this ->keywords [strtolower ($ type )];
375-
358+ /**
359+ * @psalm-suppress LessSpecificReturnStatement
360+ * @psalm-suppress InvalidStringClass
361+ */
376362 return new $ className ();
377363 }
378364
@@ -384,7 +370,7 @@ private function resolveKeyword($type)
384370 *
385371 * @return Object_
386372 */
387- private function resolveTypedObject ($ type , Context $ context = null )
373+ private function resolveTypedObject ($ type , Context $ context = null ): Object_
388374 {
389375 return new Object_ ($ this ->fqsenResolver ->resolve ($ type , $ context ));
390376 }
@@ -394,7 +380,7 @@ private function resolveTypedObject($type, Context $context = null)
394380 *
395381 * @return Array_|Collection
396382 */
397- private function resolveCollection (\ArrayIterator $ tokens , Type $ classType , Context $ context )
383+ private function resolveCollection (\ArrayIterator $ tokens , Type $ classType , Context $ context ): Type
398384 {
399385 $ isArray = ('array ' === (string ) $ classType );
400386
@@ -460,16 +446,14 @@ private function resolveCollection(\ArrayIterator $tokens, Type $classType, Cont
460446 return new Array_ ($ valueType , $ keyType );
461447 }
462448
463- if ($ classType instanceof Object_) {
464- return $ this ->makeCollectionFromObject ($ classType , $ valueType , $ keyType );
465- }
449+ return $ this ->makeCollectionFromObject ($ classType , $ valueType , $ keyType );
466450 }
467451
468452 /**
469453 * @param Type|null $keyType
470454 * @return Collection
471455 */
472- private function makeCollectionFromObject (Object_ $ object , Type $ valueType , Type $ keyType = null )
456+ private function makeCollectionFromObject (Object_ $ object , Type $ valueType , Type $ keyType = null ): Collection
473457 {
474458 return new Collection ($ object ->getFqsen (), $ valueType , $ keyType );
475459 }
0 commit comments