Skip to content

Commit

Permalink
Merge 3b9adba into 58bb724
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfnl committed Dec 22, 2020
2 parents 58bb724 + 3b9adba commit 5c01bdb
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 20 deletions.
2 changes: 2 additions & 0 deletions PHPCSUtils/BackCompat/BCTokens.php
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
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
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
17 changes: 16 additions & 1 deletion Tests/BackCompat/BCTokens/FunctionNameTokensTest.php
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 Down
3 changes: 1 addition & 2 deletions Tests/Tokens/Collections/FunctionCallTokensTest.php
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
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
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
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
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
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
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
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 5c01bdb

Please sign in to comment.