From d9ac1c5b9cda136815553e11efd5960569f44b67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=A1=D0=BF=D0=B8?= =?UTF-8?q?=D1=80=D0=BA=D0=BE=D0=B2?= Date: Sat, 13 Dec 2025 12:18:05 +0400 Subject: [PATCH 1/2] Add support for `callable-array` --- src/PseudoTypes/CallableArray.php | 38 ++++++++++++++++++++ src/TypeResolver.php | 2 ++ tests/unit/PseudoTypes/CallableArrayTest.php | 34 ++++++++++++++++++ tests/unit/TypeResolverTest.php | 2 ++ 4 files changed, 76 insertions(+) create mode 100644 src/PseudoTypes/CallableArray.php create mode 100644 tests/unit/PseudoTypes/CallableArrayTest.php diff --git a/src/PseudoTypes/CallableArray.php b/src/PseudoTypes/CallableArray.php new file mode 100644 index 0000000..824200c --- /dev/null +++ b/src/PseudoTypes/CallableArray.php @@ -0,0 +1,38 @@ + Object_::class, 'mixed' => Mixed_::class, 'array' => Array_::class, + 'callable-array' => CallableArray::class, 'array-key' => ArrayKey::class, 'non-empty-array' => NonEmptyArray::class, 'resource' => Resource_::class, diff --git a/tests/unit/PseudoTypes/CallableArrayTest.php b/tests/unit/PseudoTypes/CallableArrayTest.php new file mode 100644 index 0000000..e93d080 --- /dev/null +++ b/tests/unit/PseudoTypes/CallableArrayTest.php @@ -0,0 +1,34 @@ +assertEquals(new Array_(new Mixed_(), new Integer()), $type->underlyingType()); + } + + public function testToString(): void + { + $this->assertSame('callable-array', (string) (new CallableArray())); + } +} diff --git a/tests/unit/TypeResolverTest.php b/tests/unit/TypeResolverTest.php index 04c92c0..abc401e 100644 --- a/tests/unit/TypeResolverTest.php +++ b/tests/unit/TypeResolverTest.php @@ -18,6 +18,7 @@ use phpDocumentor\Reflection\PseudoTypes\ArrayKey; use phpDocumentor\Reflection\PseudoTypes\ArrayShape; use phpDocumentor\Reflection\PseudoTypes\ArrayShapeItem; +use phpDocumentor\Reflection\PseudoTypes\CallableArray; use phpDocumentor\Reflection\PseudoTypes\CallableString; use phpDocumentor\Reflection\PseudoTypes\ClassString; use phpDocumentor\Reflection\PseudoTypes\Conditional; @@ -668,6 +669,7 @@ public function provideKeywords(): array ['callable-string', CallableString::class], ['callback', Callable_::class], ['array', Array_::class], + ['callable-array', CallableArray::class], ['array-key', ArrayKey::class], ['scalar', Scalar::class], ['object', Object_::class], From 0fb20236f63a5f0019f23dde98c8dbcd8be5fd0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=A1=D0=BF=D0=B8?= =?UTF-8?q?=D1=80=D0=BA=D0=BE=D0=B2?= Date: Sat, 13 Dec 2025 20:14:08 +0400 Subject: [PATCH 2/2] Fixed the 'CallableArray` constructor --- src/PseudoTypes/CallableArray.php | 5 +++++ tests/unit/PseudoTypes/CallableArrayTest.php | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/PseudoTypes/CallableArray.php b/src/PseudoTypes/CallableArray.php index 824200c..2ccaaf0 100644 --- a/src/PseudoTypes/CallableArray.php +++ b/src/PseudoTypes/CallableArray.php @@ -26,6 +26,11 @@ */ final class CallableArray extends Array_ implements PseudoType { + public function __construct() + { + parent::__construct(new Mixed_(), new Integer()); + } + public function underlyingType(): Type { return new Array_(new Mixed_(), new Integer()); diff --git a/tests/unit/PseudoTypes/CallableArrayTest.php b/tests/unit/PseudoTypes/CallableArrayTest.php index e93d080..447893e 100644 --- a/tests/unit/PseudoTypes/CallableArrayTest.php +++ b/tests/unit/PseudoTypes/CallableArrayTest.php @@ -25,6 +25,8 @@ public function testCreate(): void $type = new CallableArray(); $this->assertEquals(new Array_(new Mixed_(), new Integer()), $type->underlyingType()); + $this->assertEquals(new Mixed_(), $type->getValueType()); + $this->assertEquals(new Integer(), $type->getKeyType()); } public function testToString(): void