Skip to content

Commit 7671896

Browse files
authored
Merge pull request #276 from mspirkov/add-callable-array
Add support for `callable-array`
2 parents bc91225 + 0fb2023 commit 7671896

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

src/PseudoTypes/CallableArray.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 __construct()
30+
{
31+
parent::__construct(new Mixed_(), new Integer());
32+
}
33+
34+
public function underlyingType(): Type
35+
{
36+
return new Array_(new Mixed_(), new Integer());
37+
}
38+
39+
public function __toString(): string
40+
{
41+
return 'callable-array';
42+
}
43+
}

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\ClosedResource;
@@ -169,6 +170,7 @@ final class TypeResolver
169170
'object' => Object_::class,
170171
'mixed' => Mixed_::class,
171172
'array' => Array_::class,
173+
'callable-array' => CallableArray::class,
172174
'array-key' => ArrayKey::class,
173175
'non-empty-array' => NonEmptyArray::class,
174176
'resource' => Resource_::class,
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
$this->assertEquals(new Mixed_(), $type->getValueType());
29+
$this->assertEquals(new Integer(), $type->getKeyType());
30+
}
31+
32+
public function testToString(): void
33+
{
34+
$this->assertSame('callable-array', (string) (new CallableArray()));
35+
}
36+
}

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\ClosedResource;
@@ -672,6 +673,7 @@ public function provideKeywords(): array
672673
['callable-string', CallableString::class],
673674
['callback', Callable_::class],
674675
['array', Array_::class],
676+
['callable-array', CallableArray::class],
675677
['array-key', ArrayKey::class],
676678
['scalar', Scalar::class],
677679
['object', Object_::class],

0 commit comments

Comments
 (0)