Skip to content

Commit 17726a3

Browse files
committed
Add support for never keyword
php 8.1 introduces the `never` keyword, which can be used as return type.
1 parent 5c67adb commit 17726a3

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/TypeResolver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ final class TypeResolver
107107
'static' => Types\Static_::class,
108108
'parent' => Types\Parent_::class,
109109
'iterable' => Types\Iterable_::class,
110+
'never' => Types\Never_::class,
110111
];
111112

112113
/**

src/Types/Never_.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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\Types;
15+
16+
use phpDocumentor\Reflection\Type;
17+
18+
/**
19+
* Value Object representing the pseudo-type 'never'.
20+
*
21+
* Never is generally only used when working with return types as it signifies that the method that only
22+
* ever throw or exit.
23+
*
24+
* @psalm-immutable
25+
*/
26+
final class Never_ implements Type
27+
{
28+
/**
29+
* Returns a rendered output of the Type as it would be used in a DocBlock.
30+
*/
31+
public function __toString(): string
32+
{
33+
return 'never';
34+
}
35+
}

tests/unit/TypeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@ public function provideKeywords(): array
757757
['self', Types\Self_::class],
758758
['parent', Types\Parent_::class],
759759
['iterable', Types\Iterable_::class],
760+
['never', Types\Never_::class],
760761
];
761762
}
762763

0 commit comments

Comments
 (0)