Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tokens\Collections::$returnTypeTokens: allow for "static" (PHP 8) #134

Merged
merged 1 commit into from
May 4, 2020
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 PHPCSUtils/Tokens/Collections.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ class Collections
\T_CALLABLE => \T_CALLABLE,
\T_SELF => \T_SELF,
\T_PARENT => \T_PARENT,
\T_STATIC => \T_STATIC,
\T_NS_SEPARATOR => \T_NS_SEPARATOR,
];

Expand Down
7 changes: 7 additions & 0 deletions Tests/BackCompat/BCFile/GetMethodPropertiesTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ $result = array_map(
$numbers
);

class ReturnMe {
/* testReturnTypeStatic */
private function myFunction(): static {
return $this;
}
}

/* testNotAFunction */
return true;

Expand Down
22 changes: 22 additions & 0 deletions Tests/BackCompat/BCFile/GetMethodPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,28 @@ public function testArrowFunction()
$this->getMethodPropertiesTestHelper('/* ' . __FUNCTION__ . ' */', $expected, $arrowTokenTypes);
}

/**
* Test a function with return type "static".
*
* @return void
*/
public function testReturnTypeStatic()
{
$expected = [
'scope' => 'private',
'scope_specified' => true,
'return_type' => 'static',
'return_type_token' => 7, // Offset from the T_FUNCTION token.
'nullable_return_type' => false,
'is_abstract' => false,
'is_final' => false,
'is_static' => false,
'has_body' => true,
];

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

/**
* Test for incorrect tokenization of array return type declarations in PHPCS < 2.8.0.
*
Expand Down