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
1 change: 1 addition & 0 deletions src/Standards/Generic/Sniffs/PHP/LowerCaseTypeSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class LowerCaseTypeSniff implements Sniff
'static' => true,
'false' => true,
'null' => true,
'never' => true,
];


Expand Down
4 changes: 4 additions & 0 deletions src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,7 @@ class ConstructorPropertyPromotionWithTypes {
class ConstructorPropertyPromotionAndNormalParams {
public function __construct(public Int $promotedProp, ?Int $normalArg) {}
}

function (): NeVeR {
exit;
};
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,7 @@ class ConstructorPropertyPromotionWithTypes {
class ConstructorPropertyPromotionAndNormalParams {
public function __construct(public int $promotedProp, ?int $normalArg) {}
}

function (): never {
exit;
};
1 change: 1 addition & 0 deletions src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function getErrorList()
74 => 3,
78 => 3,
82 => 2,
85 => 1,
];

}//end getErrorList()
Expand Down
9 changes: 8 additions & 1 deletion tests/Core/File/GetMethodPropertiesTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MyClass {

/* testMessyNullableReturnMethod */
public function myFunction() /* comment
*/ :
*/ :
/* comment */ ? //comment
array {}

Expand Down Expand Up @@ -126,3 +126,10 @@ interface FooBar {
/* testPHP8DuplicateTypeInUnionWhitespaceAndComment */
// Intentional fatal error - duplicate types are not allowed in union types, but that's not the concern of the method.
function duplicateTypeInUnion(): int | /*comment*/ string | INT {}

/* testPHP81NeverType */
function never(): never {}

/* testPHP81NullableNeverType */
// Intentional fatal error - nullability is not allowed with never, but that's not the concern of the method.
function nullableNever(): ?never {}
46 changes: 46 additions & 0 deletions tests/Core/File/GetMethodPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,52 @@ public function testPHP8DuplicateTypeInUnionWhitespaceAndComment()
}//end testPHP8DuplicateTypeInUnionWhitespaceAndComment()


/**
* Verify recognition of PHP8.1 type "never".
*
* @return void
*/
public function testPHP81NeverType()
{
$expected = [
'scope' => 'public',
'scope_specified' => false,
'return_type' => 'never',
'nullable_return_type' => false,
'is_abstract' => false,
'is_final' => false,
'is_static' => false,
'has_body' => true,
];

$this->getMethodPropertiesTestHelper('/* '.__FUNCTION__.' */', $expected);

}//end testPHP81NeverType()


/**
* Verify recognition of PHP8.1 type "never" with (illegal) nullability.
*
* @return void
*/
public function testPHP81NullableNeverType()
{
$expected = [
'scope' => 'public',
'scope_specified' => false,
'return_type' => '?never',
'nullable_return_type' => true,
'is_abstract' => false,
'is_final' => false,
'is_static' => false,
'has_body' => true,
];

$this->getMethodPropertiesTestHelper('/* '.__FUNCTION__.' */', $expected);

}//end testPHP81NullableNeverType()


/**
* Test helper.
*
Expand Down
3 changes: 3 additions & 0 deletions tests/Core/Tokenizer/NamedFunctionCallArgumentsTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,6 @@ foobar(parent: $value, /* testReservedKeywordParent2 */ parent: $value);

/* testReservedKeywordSelf1 */
foobar(self: $value, /* testReservedKeywordSelf2 */ self: $value);

/* testReservedKeywordNever1 */
foobar(never: $value, /* testReservedKeywordNever2 */ never: $value);
1 change: 1 addition & 0 deletions tests/Core/Tokenizer/NamedFunctionCallArgumentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ public function dataReservedKeywordsAsName()
'resource',
'mixed',
'numeric',
'never',

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