Skip to content

Commit

Permalink
Merge pull request #241 from PHPCSStandards/collections/sync-with-php…
Browse files Browse the repository at this point in the history
…cs-4.x-identifier-names

PHPCS 4.x | Sync with upstream changes regarding PHP 8 identifier names
  • Loading branch information
jrfnl committed Dec 22, 2020
2 parents edf6a35 + 5c69cbb commit 3f1a79a
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 21 deletions.
2 changes: 2 additions & 0 deletions PHPCSUtils/BackCompat/BCTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ public static function textStringTokens()
* Changelog for the PHPCS native array:
* - Introduced in PHPCS 2.3.3.
* - PHPCS 3.1.0: `T_SELF` and `T_STATIC` added to the array.
* - PHPCS 4.0.0: `T_NAME_QUALIFIED`, `T_NAME_FULLY_QUALIFIED` and `T_NAME_RELATIVE` added to the array.
*
* @see \PHP_CodeSniffer\Util\Tokens::$functionNameTokens Original array.
*
Expand All @@ -370,6 +371,7 @@ public static function functionNameTokens()
$tokens = Tokens::$functionNameTokens;
$tokens[\T_SELF] = \T_SELF;
$tokens[\T_STATIC] = \T_STATIC;
$tokens += Collections::nameTokens();

return $tokens;
}
Expand Down
6 changes: 3 additions & 3 deletions PHPCSUtils/TestUtils/UtilityMethodTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ public static function resetTestFile()
public static function usesPhp8NameTokens()
{
$version = Helper::getVersion();
if (\version_compare(\PHP_VERSION_ID, '80000', '>=') === true
&& (\version_compare($version, '3.5.7', '<') === true
|| \version_compare($version, '4.0.0', '>=') === true)
if ((\version_compare(\PHP_VERSION_ID, '80000', '>=') === true
&& \version_compare($version, '3.5.7', '<') === true)
|| \version_compare($version, '4.0.0', '>=') === true
) {
return true;
}
Expand Down
4 changes: 3 additions & 1 deletion Tests/BackCompat/BCFile/GetMethodPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,14 @@ public function testReturnNamespace()
*/
public function testReturnMultilineNamespace()
{
$php8Names = parent::usesPhp8NameTokens();

$expected = [
'scope' => 'public',
'scope_specified' => false,
'return_type' => '\MyNamespace\MyClass\Foo',
'return_type_token' => 7, // Offset from the T_FUNCTION token.
'return_type_end_token' => 23, // Offset from the T_FUNCTION token.
'return_type_end_token' => ($php8Names === true) ? 20 : 23, // Offset from the T_FUNCTION token.
'nullable_return_type' => false,
'is_abstract' => false,
'is_final' => false,
Expand Down
43 changes: 41 additions & 2 deletions Tests/BackCompat/BCTokens/FunctionNameTokensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use PHP_CodeSniffer\Util\Tokens;
use PHPCSUtils\BackCompat\BCTokens;
use PHPCSUtils\BackCompat\Helper;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -33,6 +34,7 @@ class FunctionNameTokensTest extends TestCase
*/
public function testFunctionNameTokens()
{
$version = Helper::getVersion();
$expected = [
\T_STRING => \T_STRING,
\T_EVAL => \T_EVAL,
Expand All @@ -48,7 +50,20 @@ public function testFunctionNameTokens()
\T_STATIC => \T_STATIC,
];

$this->assertSame($expected, BCTokens::functionNameTokens());
if (\version_compare(\PHP_VERSION_ID, '80000', '>=') === true
|| \version_compare($version, '3.5.7', '>=') === true
) {
$expected[\T_NAME_QUALIFIED] = \T_NAME_QUALIFIED;
$expected[\T_NAME_FULLY_QUALIFIED] = \T_NAME_FULLY_QUALIFIED;
$expected[\T_NAME_RELATIVE] = \T_NAME_RELATIVE;
}

\asort($expected);

$result = BCTokens::functionNameTokens();
\asort($result);

$this->assertSame($expected, $result);
}

/**
Expand All @@ -62,6 +77,30 @@ public function testFunctionNameTokens()
*/
public function testPHPCSFunctionNameTokens()
{
$this->assertSame(Tokens::$functionNameTokens, BCTokens::functionNameTokens());
$version = Helper::getVersion();

if (\version_compare($version, '3.99.99', '>') === true) {
$this->assertSame(Tokens::$functionNameTokens, BCTokens::functionNameTokens());
} else {
/*
* Don't fail this test on the difference between PHPCS 4.x and 3.x.
* This test is only run against `dev-master` and `dev-master` is still PHPCS 3.x.
*/
$expected = Tokens::$functionNameTokens;
if (\version_compare(\PHP_VERSION_ID, '80000', '>=') === true
|| \version_compare($version, '3.5.7', '>=') === true
) {
$expected[\T_NAME_QUALIFIED] = \T_NAME_QUALIFIED;
$expected[\T_NAME_FULLY_QUALIFIED] = \T_NAME_FULLY_QUALIFIED;
$expected[\T_NAME_RELATIVE] = \T_NAME_RELATIVE;
}

\asort($expected);

$result = BCTokens::functionNameTokens();
\asort($result);

$this->assertSame($expected, $result);
}
}
}
3 changes: 1 addition & 2 deletions Tests/Tokens/Collections/FunctionCallTokensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public function testFunctionCallTokens()
];

if (\version_compare(\PHP_VERSION_ID, '80000', '>=') === true
|| (\version_compare($version, '3.5.7', '>=') === true
&& \version_compare($version, '4.0.0', '<') === true)
|| \version_compare($version, '3.5.7', '>=') === true
) {
$expected[\T_NAME_QUALIFIED] = \T_NAME_QUALIFIED;
$expected[\T_NAME_FULLY_QUALIFIED] = \T_NAME_FULLY_QUALIFIED;
Expand Down
3 changes: 1 addition & 2 deletions Tests/Tokens/Collections/NameTokensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public function testNameTokens()
];

if (\version_compare(\PHP_VERSION_ID, '80000', '>=') === true
|| (\version_compare($version, '3.5.7', '>=') === true
&& \version_compare($version, '4.0.0', '<') === true)
|| \version_compare($version, '3.5.7', '>=') === true
) {
$expected[\T_NAME_QUALIFIED] = \T_NAME_QUALIFIED;
$expected[\T_NAME_FULLY_QUALIFIED] = \T_NAME_FULLY_QUALIFIED;
Expand Down
3 changes: 1 addition & 2 deletions Tests/Tokens/Collections/NamespacedNameTokensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public function testNamespacedNameTokens()
];

if (\version_compare(\PHP_VERSION_ID, '80000', '>=') === true
|| (\version_compare($version, '3.5.7', '>=') === true
&& \version_compare($version, '4.0.0', '<') === true)
|| \version_compare($version, '3.5.7', '>=') === true
) {
$expected[\T_NAME_QUALIFIED] = \T_NAME_QUALIFIED;
$expected[\T_NAME_FULLY_QUALIFIED] = \T_NAME_FULLY_QUALIFIED;
Expand Down
3 changes: 1 addition & 2 deletions Tests/Tokens/Collections/ParameterPassingTokensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public function testParameterPassingTokens()
];

if (\version_compare(\PHP_VERSION_ID, '80000', '>=') === true
|| (\version_compare($version, '3.5.7', '>=') === true
&& \version_compare($version, '4.0.0', '<') === true)
|| \version_compare($version, '3.5.7', '>=') === true
) {
$expected[\T_NAME_QUALIFIED] = \T_NAME_QUALIFIED;
$expected[\T_NAME_FULLY_QUALIFIED] = \T_NAME_FULLY_QUALIFIED;
Expand Down
3 changes: 1 addition & 2 deletions Tests/Tokens/Collections/ParameterTypeTokensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public function testParameterTypeTokens()
];

if (\version_compare(\PHP_VERSION_ID, '80000', '>=') === true
|| (\version_compare($version, '3.5.7', '>=') === true
&& \version_compare($version, '4.0.0', '<') === true)
|| \version_compare($version, '3.5.7', '>=') === true
) {
$expected[\T_NAME_QUALIFIED] = \T_NAME_QUALIFIED;
$expected[\T_NAME_FULLY_QUALIFIED] = \T_NAME_FULLY_QUALIFIED;
Expand Down
3 changes: 1 addition & 2 deletions Tests/Tokens/Collections/PropertyTypeTokensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public function testPropertyTypeTokens()
];

if (\version_compare(\PHP_VERSION_ID, '80000', '>=') === true
|| (\version_compare($version, '3.5.7', '>=') === true
&& \version_compare($version, '4.0.0', '<') === true)
|| \version_compare($version, '3.5.7', '>=') === true
) {
$expected[\T_NAME_QUALIFIED] = \T_NAME_QUALIFIED;
$expected[\T_NAME_FULLY_QUALIFIED] = \T_NAME_FULLY_QUALIFIED;
Expand Down
3 changes: 1 addition & 2 deletions Tests/Tokens/Collections/ReturnTypeTokensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public function testReturnTypeTokens()
];

if (\version_compare(\PHP_VERSION_ID, '80000', '>=') === true
|| (\version_compare($version, '3.5.7', '>=') === true
&& \version_compare($version, '4.0.0', '<') === true)
|| \version_compare($version, '3.5.7', '>=') === true
) {
$expected[\T_NAME_QUALIFIED] = \T_NAME_QUALIFIED;
$expected[\T_NAME_FULLY_QUALIFIED] = \T_NAME_FULLY_QUALIFIED;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Utils/PassedParameters/GetParametersNamedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function dataGetParameters()
],
3 => [
'start' => ($php8Names === true) ? 7 : 8,
'end' => ($php8Names === true) ? 7 : 11,
'end' => ($php8Names === true) ? 8 : 11,
'raw' => 'MyNS\VALUE',
],
],
Expand Down

0 comments on commit 3f1a79a

Please sign in to comment.