Skip to content

Commit 6da9eeb

Browse files
authored
Merge pull request #320 from PHPCSStandards/feature/file-getmethodproperties-extra-test
File::getMethodProperties(): add extra test with nullable static return type
2 parents c44475c + 27ce14f commit 6da9eeb

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

tests/Core/File/GetMethodPropertiesTest.inc

+5
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ class ReturnMe {
7979
private function myFunction(): static {
8080
return $this;
8181
}
82+
83+
/* testReturnTypeNullableStatic */
84+
function myNullableFunction(): ?static {
85+
return $this;
86+
}
8287
}
8388

8489
/* testPHP8MixedTypeHint */

tests/Core/File/GetMethodPropertiesTest.php

+26
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,32 @@ public function testReturnTypeStatic()
561561
}//end testReturnTypeStatic()
562562

563563

564+
/**
565+
* Test a function with return type "?static".
566+
*
567+
* @return void
568+
*/
569+
public function testReturnTypeNullableStatic()
570+
{
571+
// Offsets are relative to the T_FUNCTION token.
572+
$expected = [
573+
'scope' => 'public',
574+
'scope_specified' => false,
575+
'return_type' => '?static',
576+
'return_type_token' => 8,
577+
'return_type_end_token' => 8,
578+
'nullable_return_type' => true,
579+
'is_abstract' => false,
580+
'is_final' => false,
581+
'is_static' => false,
582+
'has_body' => true,
583+
];
584+
585+
$this->getMethodPropertiesTestHelper('/* '.__FUNCTION__.' */', $expected);
586+
587+
}//end testReturnTypeNullableStatic()
588+
589+
564590
/**
565591
* Test a function with return type "mixed".
566592
*

0 commit comments

Comments
 (0)