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

Collections::propertyTypeTokens[BC](): support the PHP 8 identifier name tokens #207

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
23 changes: 13 additions & 10 deletions PHPCSUtils/Tokens/Collections.php
Original file line number Diff line number Diff line change
Expand Up @@ -837,22 +837,24 @@ public static function parameterTypeTokensBC()
*
* @since 1.0.0-alpha4 This method replaces the {@see Collections::$propertyTypeTokens} property.
* @since 1.0.0-alpha4 Added support for PHP 8.0 union types.
* @since 1.0.0-alpha4 Added support for PHP 8.0 identifier name tokens.
*
* @return array <int|string> => <int|string>
*/
public static function propertyTypeTokens()
{
return [
\T_CALLABLE => \T_CALLABLE,
\T_SELF => \T_SELF,
\T_PARENT => \T_PARENT,
\T_FALSE => \T_FALSE, // Union types only.
\T_NULL => \T_NULL, // Union types only.
\T_STRING => \T_STRING,
\T_NAMESPACE => \T_NAMESPACE,
\T_NS_SEPARATOR => \T_NS_SEPARATOR,
\T_BITWISE_OR => \T_BITWISE_OR, // Union types.
$tokens = [
\T_CALLABLE => \T_CALLABLE,
\T_SELF => \T_SELF,
\T_PARENT => \T_PARENT,
\T_FALSE => \T_FALSE, // Union types only.
\T_NULL => \T_NULL, // Union types only.
\T_BITWISE_OR => \T_BITWISE_OR, // Union types.
];

$tokens += self::namespacedNameTokens();

return $tokens;
}

/**
Expand All @@ -873,6 +875,7 @@ public static function propertyTypeTokens()
*
* @since 1.0.0-alpha3
* @since 1.0.0-alpha4 Added support for PHP 8.0 union types.
* @since 1.0.0-alpha4 Added support for PHP 8.0 identifier name tokens.
*
* @return array <int|string> => <int|string>
*/
Expand Down
1 change: 1 addition & 0 deletions PHPCSUtils/Utils/Variables.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class Variables
* - Defensive coding against incorrect calls to this method.
* - Support for PHP 8.0 union types.
* - Support for namespace operator in type declarations.
* - Support PHP 8.0 identifier name tokens in property types, cross-version PHP & PHPCS.
*
* @see \PHP_CodeSniffer\Files\File::getMemberProperties() Original source.
* @see \PHPCSUtils\BackCompat\BCFile::getMemberProperties() Cross-version compatible version of the original.
Expand Down
12 changes: 9 additions & 3 deletions Tests/Tokens/Collections/PropertyTypeTokensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ public function testPropertyTypeTokens()
\T_PARENT => \T_PARENT,
\T_FALSE => \T_FALSE,
\T_NULL => \T_NULL,
\T_STRING => \T_STRING,
\T_NAMESPACE => \T_NAMESPACE,
\T_NS_SEPARATOR => \T_NS_SEPARATOR,
\T_BITWISE_OR => \T_BITWISE_OR,
\T_NS_SEPARATOR => \T_NS_SEPARATOR,
\T_NAMESPACE => \T_NAMESPACE,
\T_STRING => \T_STRING,
];

if (\version_compare(\PHP_VERSION_ID, '80000', '>=') === true) {
$expected[\T_NAME_QUALIFIED] = \T_NAME_QUALIFIED;
$expected[\T_NAME_FULLY_QUALIFIED] = \T_NAME_FULLY_QUALIFIED;
$expected[\T_NAME_RELATIVE] = \T_NAME_RELATIVE;
}

$this->assertSame($expected, Collections::propertyTypeTokens());
}
}