Skip to content

Commit d9ac1c5

Browse files
committed
Add support for callable-array
1 parent fcadea7 commit d9ac1c5

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

src/PseudoTypes/CallableArray.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link http://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Reflection\PseudoTypes;
15+
16+
use phpDocumentor\Reflection\PseudoType;
17+
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\Types\Array_;
19+
use phpDocumentor\Reflection\Types\Integer;
20+
use phpDocumentor\Reflection\Types\Mixed_;
21+
22+
/**
23+
* Value Object representing the type 'callable-array'.
24+
*
25+
* @psalm-immutable
26+
*/
27+
final class CallableArray extends Array_ implements PseudoType
28+
{
29+
public function underlyingType(): Type
30+
{
31+
return new Array_(new Mixed_(), new Integer());
32+
}
33+
34+
public function __toString(): string
35+
{
36+
return 'callable-array';
37+
}
38+
}

src/TypeResolver.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use phpDocumentor\Reflection\PseudoTypes\ArrayKey;
1919
use phpDocumentor\Reflection\PseudoTypes\ArrayShape;
2020
use phpDocumentor\Reflection\PseudoTypes\ArrayShapeItem;
21+
use phpDocumentor\Reflection\PseudoTypes\CallableArray;
2122
use phpDocumentor\Reflection\PseudoTypes\CallableString;
2223
use phpDocumentor\Reflection\PseudoTypes\ClassString;
2324
use phpDocumentor\Reflection\PseudoTypes\Conditional;
@@ -167,6 +168,7 @@ final class TypeResolver
167168
'object' => Object_::class,
168169
'mixed' => Mixed_::class,
169170
'array' => Array_::class,
171+
'callable-array' => CallableArray::class,
170172
'array-key' => ArrayKey::class,
171173
'non-empty-array' => NonEmptyArray::class,
172174
'resource' => Resource_::class,
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link http://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Reflection\PseudoTypes;
15+
16+
use phpDocumentor\Reflection\Types\Array_;
17+
use phpDocumentor\Reflection\Types\Integer;
18+
use phpDocumentor\Reflection\Types\Mixed_;
19+
use PHPUnit\Framework\TestCase;
20+
21+
final class CallableArrayTest extends TestCase
22+
{
23+
public function testCreate(): void
24+
{
25+
$type = new CallableArray();
26+
27+
$this->assertEquals(new Array_(new Mixed_(), new Integer()), $type->underlyingType());
28+
}
29+
30+
public function testToString(): void
31+
{
32+
$this->assertSame('callable-array', (string) (new CallableArray()));
33+
}
34+
}

tests/unit/TypeResolverTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use phpDocumentor\Reflection\PseudoTypes\ArrayKey;
1919
use phpDocumentor\Reflection\PseudoTypes\ArrayShape;
2020
use phpDocumentor\Reflection\PseudoTypes\ArrayShapeItem;
21+
use phpDocumentor\Reflection\PseudoTypes\CallableArray;
2122
use phpDocumentor\Reflection\PseudoTypes\CallableString;
2223
use phpDocumentor\Reflection\PseudoTypes\ClassString;
2324
use phpDocumentor\Reflection\PseudoTypes\Conditional;
@@ -668,6 +669,7 @@ public function provideKeywords(): array
668669
['callable-string', CallableString::class],
669670
['callback', Callable_::class],
670671
['array', Array_::class],
672+
['callable-array', CallableArray::class],
671673
['array-key', ArrayKey::class],
672674
['scalar', Scalar::class],
673675
['object', Object_::class],

0 commit comments

Comments
 (0)