-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for non-empty-array notation
- Loading branch information
Showing
5 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\Mixed_; | ||
|
||
final class NonEmptyArray extends Array_ implements PseudoType | ||
Check failure on line 21 in src/PseudoTypes/NonEmptyArray.php GitHub Actions / Static analysis / Static Code Analysis (8.0)MissingImmutableAnnotation
Check failure on line 21 in src/PseudoTypes/NonEmptyArray.php GitHub Actions / Static analysis / Static Code Analysis (8.0)MissingImmutableAnnotation
|
||
{ | ||
public function underlyingType(): Type | ||
{ | ||
return new Array_($this->valueType, $this->keyType); | ||
} | ||
|
||
/** | ||
* Returns a rendered output of the Type as it would be used in a DocBlock. | ||
*/ | ||
public function __toString(): string | ||
Check failure on line 31 in src/PseudoTypes/NonEmptyArray.php GitHub Actions / Static analysis / Static Code Analysis (8.0)MissingImmutableAnnotation
|
||
{ | ||
if ($this->keyType) { | ||
return 'non-empty-array<' . $this->keyType . ',' . $this->valueType . '>'; | ||
} | ||
|
||
if ($this->valueType instanceof Mixed_) { | ||
return 'non-empty-array'; | ||
} | ||
|
||
return 'non-empty-array<' . $this->valueType . '>'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?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\Compound; | ||
use phpDocumentor\Reflection\Types\Integer; | ||
use phpDocumentor\Reflection\Types\Mixed_; | ||
use phpDocumentor\Reflection\Types\String_; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @coversDefaultClass \phpDocumentor\Reflection\PseudoTypes\NonEmptyArray | ||
*/ | ||
class NonEmptyArrayTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider provideArrays | ||
* @covers ::__toString | ||
*/ | ||
public function testArrayStringifyCorrectly(NonEmptyArray $array, string $expectedString): void | ||
{ | ||
$this->assertSame($expectedString, (string) $array); | ||
} | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
public function provideArrays(): array | ||
{ | ||
return [ | ||
'simple non-empty-array' => [new NonEmptyArray(), 'non-empty-array'], | ||
'non-empty-array of mixed' => [new NonEmptyArray(new Mixed_()), 'non-empty-array'], | ||
'non-empty-array of single type' => [new NonEmptyArray(new String_()), 'non-empty-array<string>'], | ||
'non-empty-array of compound type' => | ||
[new NonEmptyArray(new Compound([new Integer(), new String_()]), new String_()), 'non-empty-array<string,int|string>'], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters