diff --git a/src/Nullability/NullableChecker.php b/src/Nullability/NullableChecker.php index 94de481..a757977 100644 --- a/src/Nullability/NullableChecker.php +++ b/src/Nullability/NullableChecker.php @@ -121,11 +121,6 @@ public function visitClassString(Type\ClassStringType $type): mixed return false; } - public function visitCallableString(Type\CallableStringType $type): mixed - { - return false; - } - public function visitInterfaceString(Type\InterfaceStringType $type): mixed { return false; @@ -191,11 +186,6 @@ public function visitNonEmptyArray(Type\NonEmptyArrayType $type): mixed return false; } - public function visitCallableArray(Type\CallableArrayType $type): mixed - { - return false; - } - public function visitArray(Type\ArrayType $type): mixed { return false; diff --git a/src/PhpDocParser/ContextualPhpDocTypeReflector.php b/src/PhpDocParser/ContextualPhpDocTypeReflector.php index fdd8ecb..b8a7133 100644 --- a/src/PhpDocParser/ContextualPhpDocTypeReflector.php +++ b/src/PhpDocParser/ContextualPhpDocTypeReflector.php @@ -165,11 +165,20 @@ private function reflectIdentifier(string $name, array $genericTypes = []): Type 'array-key' => types::arrayKey, 'literal-int' => types::literalInt, 'literal-string' => types::literalString, - 'callable-string' => types::callableString, + 'callable-string' => types::intersection( + types::literalString, + types::callable(), + ), 'interface-string' => types::interfaceString, 'enum-string' => types::enumString, 'trait-string' => types::traitString, - 'callable-array' => types::callableArray, + 'callable-array' => types::intersection( + types::arrayShape([ + types::union(types::classString, types::object), + types::literalString, + ]), + types::callable(), + ), 'resource' => types::resource, 'closed-resource' => types::closedResource, 'object' => types::object, diff --git a/src/TypeResolver/RecursiveTypeReplacer.php b/src/TypeResolver/RecursiveTypeReplacer.php index f897a79..284d24b 100644 --- a/src/TypeResolver/RecursiveTypeReplacer.php +++ b/src/TypeResolver/RecursiveTypeReplacer.php @@ -116,11 +116,6 @@ public function visitClassString(Type\ClassStringType $type): mixed return $type; } - public function visitCallableString(Type\CallableStringType $type): mixed - { - return $type; - } - public function visitInterfaceString(Type\InterfaceStringType $type): mixed { return $type; @@ -198,11 +193,6 @@ public function visitNonEmptyArray(Type\NonEmptyArrayType $type): mixed return types::nonEmptyArray($type->keyType->accept($this), $type->valueType->accept($this)); } - public function visitCallableArray(Type\CallableArrayType $type): mixed - { - return $type; - } - public function visitArray(Type\ArrayType $type): mixed { /** @psalm-suppress MixedArgumentTypeCoercion */ diff --git a/tests/unit/PhpDocParser/ContextualPhpDocTypeReflectorTest.php b/tests/unit/PhpDocParser/ContextualPhpDocTypeReflectorTest.php index e067f40..5b9440d 100644 --- a/tests/unit/PhpDocParser/ContextualPhpDocTypeReflectorTest.php +++ b/tests/unit/PhpDocParser/ContextualPhpDocTypeReflectorTest.php @@ -71,7 +71,10 @@ public static function validTypes(): \Generator yield ['literal-string', types::literalString]; yield ['numeric-string', types::numericString]; yield ['class-string', types::classString]; - yield ['callable-string', types::callableString]; + yield ['callable-string', types::intersection( + types::literalString, + types::callable(), + )]; yield ['interface-string', types::interfaceString]; yield ['enum-string', types::enumString]; yield ['trait-string', types::traitString]; @@ -81,7 +84,13 @@ public static function validTypes(): \Generator yield ['string', types::string]; yield ['numeric', types::numeric]; yield ['scalar', types::scalar]; - yield ['callable-array', types::callableArray]; + yield ['callable-array', types::intersection( + types::arrayShape([ + types::union(types::classString, types::object), + types::literalString, + ]), + types::callable(), + )]; yield ['object', types::object]; yield ['resource', types::resource]; yield ['closed-resource', types::closedResource];