Skip to content

Commit

Permalink
Merge pull request #207 from PHPCSStandards/php-8.0/collections-prope…
Browse files Browse the repository at this point in the history
…rtytypetokens-support-identifier-name-tokens

Collections::propertyTypeTokens[BC](): support the PHP 8 identifier name tokens
  • Loading branch information
jrfnl committed Sep 13, 2020
2 parents 85f43a9 + 6ffba3f commit a7d08fd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
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());
}
}

0 comments on commit a7d08fd

Please sign in to comment.