Skip to content

Commit 502e62a

Browse files
committed
2 parents 9d4c6d1 + 01be758 commit 502e62a

File tree

8 files changed

+68
-1
lines changed

8 files changed

+68
-1
lines changed

src/Standards/Generic/Sniffs/PHP/LowerCaseTypeSniff.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class LowerCaseTypeSniff implements Sniff
3838
'static' => true,
3939
'false' => true,
4040
'null' => true,
41+
'never' => true,
4142
];
4243

4344

src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,7 @@ class ConstructorPropertyPromotionWithTypes {
8181
class ConstructorPropertyPromotionAndNormalParams {
8282
public function __construct(public Int $promotedProp, ?Int $normalArg) {}
8383
}
84+
85+
function (): NeVeR {
86+
exit;
87+
};

src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc.fixed

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,7 @@ class ConstructorPropertyPromotionWithTypes {
8181
class ConstructorPropertyPromotionAndNormalParams {
8282
public function __construct(public int $promotedProp, ?int $normalArg) {}
8383
}
84+
85+
function (): never {
86+
exit;
87+
};

src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function getErrorList()
6565
74 => 3,
6666
78 => 3,
6767
82 => 2,
68+
85 => 1,
6869
];
6970

7071
}//end getErrorList()

tests/Core/File/GetMethodPropertiesTest.inc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class MyClass {
3333

3434
/* testMessyNullableReturnMethod */
3535
public function myFunction() /* comment
36-
*/ :
36+
*/ :
3737
/* comment */ ? //comment
3838
array {}
3939

@@ -126,3 +126,10 @@ interface FooBar {
126126
/* testPHP8DuplicateTypeInUnionWhitespaceAndComment */
127127
// Intentional fatal error - duplicate types are not allowed in union types, but that's not the concern of the method.
128128
function duplicateTypeInUnion(): int | /*comment*/ string | INT {}
129+
130+
/* testPHP81NeverType */
131+
function never(): never {}
132+
133+
/* testPHP81NullableNeverType */
134+
// Intentional fatal error - nullability is not allowed with never, but that's not the concern of the method.
135+
function nullableNever(): ?never {}

tests/Core/File/GetMethodPropertiesTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,52 @@ public function testPHP8DuplicateTypeInUnionWhitespaceAndComment()
728728
}//end testPHP8DuplicateTypeInUnionWhitespaceAndComment()
729729

730730

731+
/**
732+
* Verify recognition of PHP8.1 type "never".
733+
*
734+
* @return void
735+
*/
736+
public function testPHP81NeverType()
737+
{
738+
$expected = [
739+
'scope' => 'public',
740+
'scope_specified' => false,
741+
'return_type' => 'never',
742+
'nullable_return_type' => false,
743+
'is_abstract' => false,
744+
'is_final' => false,
745+
'is_static' => false,
746+
'has_body' => true,
747+
];
748+
749+
$this->getMethodPropertiesTestHelper('/* '.__FUNCTION__.' */', $expected);
750+
751+
}//end testPHP81NeverType()
752+
753+
754+
/**
755+
* Verify recognition of PHP8.1 type "never" with (illegal) nullability.
756+
*
757+
* @return void
758+
*/
759+
public function testPHP81NullableNeverType()
760+
{
761+
$expected = [
762+
'scope' => 'public',
763+
'scope_specified' => false,
764+
'return_type' => '?never',
765+
'nullable_return_type' => true,
766+
'is_abstract' => false,
767+
'is_final' => false,
768+
'is_static' => false,
769+
'has_body' => true,
770+
];
771+
772+
$this->getMethodPropertiesTestHelper('/* '.__FUNCTION__.' */', $expected);
773+
774+
}//end testPHP81NullableNeverType()
775+
776+
731777
/**
732778
* Test helper.
733779
*

tests/Core/Tokenizer/NamedFunctionCallArgumentsTest.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,6 @@ foobar(parent: $value, /* testReservedKeywordParent2 */ parent: $value);
396396

397397
/* testReservedKeywordSelf1 */
398398
foobar(self: $value, /* testReservedKeywordSelf2 */ self: $value);
399+
400+
/* testReservedKeywordNever1 */
401+
foobar(never: $value, /* testReservedKeywordNever2 */ never: $value);

tests/Core/Tokenizer/NamedFunctionCallArgumentsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,7 @@ public function dataReservedKeywordsAsName()
831831
'resource',
832832
'mixed',
833833
'numeric',
834+
'never',
834835

835836
// Not reserved keyword, but do have their own token in PHPCS.
836837
'parent',

0 commit comments

Comments
 (0)