Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/PseudoTypes/CallableArray.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/

namespace phpDocumentor\Reflection\PseudoTypes;

use phpDocumentor\Reflection\PseudoType;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\Types\Array_;
use phpDocumentor\Reflection\Types\Integer;
use phpDocumentor\Reflection\Types\Mixed_;

/**
* Value Object representing the type 'callable-array'.
*
* @psalm-immutable
*/
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());
}

public function __toString(): string
{
return 'callable-array';
}
}
2 changes: 2 additions & 0 deletions src/TypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -167,6 +168,7 @@ final class TypeResolver
'object' => Object_::class,
'mixed' => Mixed_::class,
'array' => Array_::class,
'callable-array' => CallableArray::class,
'array-key' => ArrayKey::class,
'non-empty-array' => NonEmptyArray::class,
'resource' => Resource_::class,
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/PseudoTypes/CallableArrayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/

namespace phpDocumentor\Reflection\PseudoTypes;

use phpDocumentor\Reflection\Types\Array_;
use phpDocumentor\Reflection\Types\Integer;
use phpDocumentor\Reflection\Types\Mixed_;
use PHPUnit\Framework\TestCase;

final class CallableArrayTest extends TestCase
{
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
{
$this->assertSame('callable-array', (string) (new CallableArray()));
}
}
2 changes: 2 additions & 0 deletions tests/unit/TypeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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],
Expand Down