Skip to content

Commit 1ddb2e7

Browse files
authored
Merge pull request #272 from mspirkov/add-pseudo-bottom-types
Add support for `never-return`, `never-returns` and `no-return`
2 parents 878b6f2 + a9a0d21 commit 1ddb2e7

File tree

9 files changed

+217
-1
lines changed

9 files changed

+217
-1
lines changed

src/PseudoTypes/NeverReturn.php

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\PseudoType;
17+
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\Types\Never_;
19+
20+
/**
21+
* Value Object representing the type 'never-return'.
22+
*
23+
* @psalm-immutable
24+
*/
25+
final class NeverReturn extends Never_ implements PseudoType
26+
{
27+
public function underlyingType(): Type
28+
{
29+
return new Never_();
30+
}
31+
32+
public function __toString(): string
33+
{
34+
return 'never-return';
35+
}
36+
}

src/PseudoTypes/NeverReturns.php

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\PseudoType;
17+
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\Types\Never_;
19+
20+
/**
21+
* Value Object representing the type 'never-returns'.
22+
*
23+
* @psalm-immutable
24+
*/
25+
final class NeverReturns extends Never_ implements PseudoType
26+
{
27+
public function underlyingType(): Type
28+
{
29+
return new Never_();
30+
}
31+
32+
public function __toString(): string
33+
{
34+
return 'never-returns';
35+
}
36+
}

src/PseudoTypes/NoReturn.php

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\PseudoType;
17+
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\Types\Never_;
19+
20+
/**
21+
* Value Object representing the type 'no-return'.
22+
*
23+
* @psalm-immutable
24+
*/
25+
final class NoReturn extends Never_ implements PseudoType
26+
{
27+
public function underlyingType(): Type
28+
{
29+
return new Never_();
30+
}
31+
32+
public function __toString(): string
33+
{
34+
return 'no-return';
35+
}
36+
}

src/TypeResolver.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
use phpDocumentor\Reflection\PseudoTypes\LiteralString;
4141
use phpDocumentor\Reflection\PseudoTypes\LowercaseString;
4242
use phpDocumentor\Reflection\PseudoTypes\NegativeInteger;
43+
use phpDocumentor\Reflection\PseudoTypes\NeverReturn;
44+
use phpDocumentor\Reflection\PseudoTypes\NeverReturns;
4345
use phpDocumentor\Reflection\PseudoTypes\NonEmptyArray;
4446
use phpDocumentor\Reflection\PseudoTypes\NonEmptyList;
4547
use phpDocumentor\Reflection\PseudoTypes\NonEmptyLowercaseString;
@@ -48,6 +50,7 @@
4850
use phpDocumentor\Reflection\PseudoTypes\NonNegativeInteger;
4951
use phpDocumentor\Reflection\PseudoTypes\NonPositiveInteger;
5052
use phpDocumentor\Reflection\PseudoTypes\NonZeroInteger;
53+
use phpDocumentor\Reflection\PseudoTypes\NoReturn;
5154
use phpDocumentor\Reflection\PseudoTypes\Numeric_;
5255
use phpDocumentor\Reflection\PseudoTypes\NumericString;
5356
use phpDocumentor\Reflection\PseudoTypes\ObjectShape;
@@ -182,6 +185,9 @@ final class TypeResolver
182185
'parent' => Parent_::class,
183186
'iterable' => Iterable_::class,
184187
'never' => Never_::class,
188+
'never-return' => NeverReturn::class,
189+
'never-returns' => NeverReturns::class,
190+
'no-return' => NoReturn::class,
185191
'list' => List_::class,
186192
'non-empty-list' => NonEmptyList::class,
187193
'non-falsy-string' => NonFalsyString::class,

src/Types/Never_.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
* @psalm-immutable
2525
*/
26-
final class Never_ implements Type
26+
class Never_ implements Type
2727
{
2828
/**
2929
* Returns a rendered output of the Type as it would be used in a DocBlock.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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\Never_;
17+
use PHPUnit\Framework\TestCase;
18+
19+
final class NeverReturnTest extends TestCase
20+
{
21+
public function testCreate(): void
22+
{
23+
$type = new NeverReturn();
24+
25+
$this->assertEquals(new Never_(), $type->underlyingType());
26+
}
27+
28+
public function testToString(): void
29+
{
30+
$this->assertSame('never-return', (string) (new NeverReturn()));
31+
}
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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\Never_;
17+
use PHPUnit\Framework\TestCase;
18+
19+
final class NeverReturnsTest extends TestCase
20+
{
21+
public function testCreate(): void
22+
{
23+
$type = new NeverReturns();
24+
25+
$this->assertEquals(new Never_(), $type->underlyingType());
26+
}
27+
28+
public function testToString(): void
29+
{
30+
$this->assertSame('never-returns', (string) (new NeverReturns()));
31+
}
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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\Never_;
17+
use PHPUnit\Framework\TestCase;
18+
19+
final class NoReturnTest extends TestCase
20+
{
21+
public function testCreate(): void
22+
{
23+
$type = new NoReturn();
24+
25+
$this->assertEquals(new Never_(), $type->underlyingType());
26+
}
27+
28+
public function testToString(): void
29+
{
30+
$this->assertSame('no-return', (string) (new NoReturn()));
31+
}
32+
}

tests/unit/TypeResolverTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
use phpDocumentor\Reflection\PseudoTypes\LiteralString;
4141
use phpDocumentor\Reflection\PseudoTypes\LowercaseString;
4242
use phpDocumentor\Reflection\PseudoTypes\NegativeInteger;
43+
use phpDocumentor\Reflection\PseudoTypes\NeverReturn;
44+
use phpDocumentor\Reflection\PseudoTypes\NeverReturns;
4345
use phpDocumentor\Reflection\PseudoTypes\NonEmptyArray;
4446
use phpDocumentor\Reflection\PseudoTypes\NonEmptyList;
4547
use phpDocumentor\Reflection\PseudoTypes\NonEmptyLowercaseString;
@@ -48,6 +50,7 @@
4850
use phpDocumentor\Reflection\PseudoTypes\NonNegativeInteger;
4951
use phpDocumentor\Reflection\PseudoTypes\NonPositiveInteger;
5052
use phpDocumentor\Reflection\PseudoTypes\NonZeroInteger;
53+
use phpDocumentor\Reflection\PseudoTypes\NoReturn;
5154
use phpDocumentor\Reflection\PseudoTypes\Numeric_;
5255
use phpDocumentor\Reflection\PseudoTypes\NumericString;
5356
use phpDocumentor\Reflection\PseudoTypes\ObjectShape;
@@ -676,6 +679,9 @@ public function provideKeywords(): array
676679
['parent', Parent_::class],
677680
['iterable', Iterable_::class],
678681
['never', Never_::class],
682+
['never-return', NeverReturn::class],
683+
['never-returns', NeverReturns::class],
684+
['no-return', NoReturn::class],
679685
['literal-string', LiteralString::class],
680686
['list', List_::class],
681687
['non-empty-list', NonEmptyList::class],

0 commit comments

Comments
 (0)