Skip to content

Commit

Permalink
Merge bc04066 into fcdd2f8
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfnl committed Jun 28, 2022
2 parents fcdd2f8 + bc04066 commit 6183442
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 55 deletions.
2 changes: 1 addition & 1 deletion PHPCSUtils/BackCompat/BCFile.php
Expand Up @@ -518,7 +518,7 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr)
$nullableType = false;
$visibilityToken = null;

$paramCount++;
++$paramCount;
break;
case 'T_EQUAL':
$defaultStart = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true);
Expand Down
8 changes: 3 additions & 5 deletions PHPCSUtils/BackCompat/BCTokens.php
Expand Up @@ -436,11 +436,9 @@ public static function textStringTokens()
*/
public static function functionNameTokens()
{
$tokens = Tokens::$functionNameTokens;
$tokens[\T_SELF] = \T_SELF;
$tokens[\T_STATIC] = \T_STATIC;
$tokens[\T_PARENT] = \T_PARENT;
$tokens += Collections::nameTokens();
$tokens = Tokens::$functionNameTokens;
$tokens += Collections::ooHierarchyKeywords();
$tokens += Collections::nameTokens();

return $tokens;
}
Expand Down
70 changes: 34 additions & 36 deletions PHPCSUtils/Tokens/Collections.php
Expand Up @@ -850,6 +850,39 @@ public static function nameTokens()
return $tokens;
}

/**
* Tokens which can represent the nullsafe object operator.
*
* This method will return the appropriate tokens based on the PHP/PHPCS version used.
*
* Note: this is a method, not a property as the `T_NULLSAFE_OBJECT_OPERATOR` token may not exist.
*
* Note: if this method is used, the {@see \PHPCSUtils\Utils\Operators::isNullsafeObjectOperator()}
* method needs to be used on potential nullsafe object operator tokens to verify whether it really
* is a nullsafe object operator or not.
*
* @see \PHPCSUtils\Utils\Operators::isNullsafeObjectOperator() Nullsafe object operator detection for
* PHPCS < 3.5.7.
*
* @since 1.0.0-alpha4
*
* @return array <int|string> => <int|string>
*/
public static function nullsafeObjectOperatorBC()
{
if (TokenHelper::tokenExists('T_NULLSAFE_OBJECT_OPERATOR') === true) {
// PHP >= 8.0 / PHPCS >= 3.5.7.
return [
\T_NULLSAFE_OBJECT_OPERATOR => \T_NULLSAFE_OBJECT_OPERATOR,
];
}

return [
\T_INLINE_THEN => \T_INLINE_THEN,
\T_OBJECT_OPERATOR => \T_OBJECT_OPERATOR,
];
}

/**
* Object operators.
*
Expand Down Expand Up @@ -996,39 +1029,6 @@ public static function ooPropertyScopes()
return self::$OOPropertyScopes;
}

/**
* Tokens which can represent the nullsafe object operator.
*
* This method will return the appropriate tokens based on the PHP/PHPCS version used.
*
* Note: this is a method, not a property as the `T_NULLSAFE_OBJECT_OPERATOR` token may not exist.
*
* Note: if this method is used, the {@see \PHPCSUtils\Utils\Operators::isNullsafeObjectOperator()}
* method needs to be used on potential nullsafe object operator tokens to verify whether it really
* is a nullsafe object operator or not.
*
* @see \PHPCSUtils\Utils\Operators::isNullsafeObjectOperator() Nullsafe object operator detection for
* PHPCS < 3.5.7.
*
* @since 1.0.0-alpha4
*
* @return array <int|string> => <int|string>
*/
public static function nullsafeObjectOperatorBC()
{
if (TokenHelper::tokenExists('T_NULLSAFE_OBJECT_OPERATOR') === true) {
// PHP >= 8.0 / PHPCS >= 3.5.7.
return [
\T_NULLSAFE_OBJECT_OPERATOR => \T_NULLSAFE_OBJECT_OPERATOR,
];
}

return [
\T_INLINE_THEN => \T_INLINE_THEN,
\T_OBJECT_OPERATOR => \T_OBJECT_OPERATOR,
];
}

/**
* Tokens which can be passed to the methods in the PassedParameter class.
*
Expand Down Expand Up @@ -1272,15 +1272,13 @@ public static function returnTypeTokens()
{
$tokens = [
\T_CALLABLE => \T_CALLABLE,
\T_SELF => \T_SELF,
\T_PARENT => \T_PARENT,
\T_STATIC => \T_STATIC,
\T_FALSE => \T_FALSE, // Union types only.
\T_NULL => \T_NULL, // Union types only.
\T_ARRAY => \T_ARRAY, // Arrow functions PHPCS < 3.5.4 + union types.
\T_BITWISE_OR => \T_BITWISE_OR, // Union types for PHPCS < 3.6.0.
];

$tokens += self::ooHierarchyKeywords();
$tokens += self::namespacedNameTokens();

// PHPCS > 3.6.0: a new token was introduced for the union type separator.
Expand Down
2 changes: 1 addition & 1 deletion PHPCSUtils/Utils/FunctionDeclarations.php
Expand Up @@ -590,7 +590,7 @@ public static function getParameters(File $phpcsFile, $stackPtr)
$nullableType = false;
$visibilityToken = null;

$paramCount++;
++$paramCount;
break;

case 'T_EQUAL':
Expand Down
2 changes: 1 addition & 1 deletion PHPCSUtils/Utils/Numbers.php
Expand Up @@ -268,7 +268,7 @@ public static function getCompleteNumber(File $phpcsFile, $stackPtr)
&& $tokens[($stackPtr + 1)]['code'] === \T_STRING
&& \strtolower($tokens[($stackPtr + 1)]['content'][0]) === 'o'
&& $tokens[($stackPtr + 1)]['content'][1] !== '_'
&& preg_match('`^(o[0-7]+(?:_[0-7]+)?)[0-9_]*`i', $tokens[($stackPtr + 1)]['content'], $matches) === 1
&& \preg_match('`^(o[0-7]+(?:_[0-7]+)?)[0-9_]*`i', $tokens[($stackPtr + 1)]['content'], $matches) === 1
) {
$content .= $matches[1];
$result = self::updateResult($result, $content, ($stackPtr + 1), true);
Expand Down
2 changes: 1 addition & 1 deletion PHPCSUtils/Utils/PassedParameters.php
Expand Up @@ -333,7 +333,7 @@ public static function getParameters(File $phpcsFile, $stackPtr, $limit = 0, $is

// Prepare for the next parameter.
$paramStart = ($nextComma + 1);
$cnt++;
++$cnt;
}

return $parameters;
Expand Down
2 changes: 1 addition & 1 deletion PHPCSUtils/Utils/UseStatements.php
Expand Up @@ -221,7 +221,7 @@ public static function splitImportUseStatement(File $phpcsFile, $stackPtr)
return $statements;
}

$endOfStatement++;
++$endOfStatement;

$start = true;
$useGroup = false;
Expand Down
2 changes: 1 addition & 1 deletion Tests/BackCompat/Helper/GetCommandLineDataTest.php
Expand Up @@ -34,7 +34,7 @@ class GetCommandLineDataTest extends UtilityMethodTestCase
*/
public static function setUpTestFile()
{
self::$caseFile = dirname(dirname(__DIR__)) . '/DummyFile.inc';
self::$caseFile = \dirname(\dirname(__DIR__)) . '/DummyFile.inc';
parent::setUpTestFile();
}

Expand Down
Expand Up @@ -10,8 +10,6 @@

namespace PHPCSUtils\Tests\TestUtils\UtilityMethodTestCase;

use PHP_CodeSniffer\Exceptions\RuntimeException;
use PHP_CodeSniffer\Exceptions\TokenizerException;
use PHPCSUtils\Tests\PolyfilledTestCase;

/**
Expand Down
6 changes: 3 additions & 3 deletions Tests/Tokens/Collections/ReturnTypeTokensTest.php
Expand Up @@ -36,13 +36,13 @@ public function testReturnTypeTokens()
$version = Helper::getVersion();
$expected = [
\T_CALLABLE => \T_CALLABLE,
\T_SELF => \T_SELF,
\T_PARENT => \T_PARENT,
\T_STATIC => \T_STATIC,
\T_FALSE => \T_FALSE,
\T_NULL => \T_NULL,
\T_ARRAY => \T_ARRAY,
\T_BITWISE_OR => \T_BITWISE_OR,
\T_PARENT => \T_PARENT,
\T_SELF => \T_SELF,
\T_STATIC => \T_STATIC,
\T_NS_SEPARATOR => \T_NS_SEPARATOR,
\T_NAMESPACE => \T_NAMESPACE,
\T_STRING => \T_STRING,
Expand Down
2 changes: 1 addition & 1 deletion Tests/Utils/FunctionDeclarations/GetParametersDiffTest.php
Expand Up @@ -37,7 +37,7 @@ class GetParametersDiffTest extends UtilityMethodTestCase
*/
public static function setUpTestFile()
{
self::$caseFile = dirname(dirname(__DIR__)) . '/DummyFile.inc';
self::$caseFile = \dirname(\dirname(__DIR__)) . '/DummyFile.inc';
parent::setUpTestFile();
}

Expand Down
Expand Up @@ -132,7 +132,7 @@ public function testGetArrowFunctionOpenClose($testMarker, $expected, $targetCon
$stackPtr = $this->getTargetToken($testMarker, $targets, $targetContent);

// Change from offsets to absolute token positions.
if ($expected['get'] != false) {
if ($expected['get'] !== false) {
foreach ($expected['get'] as $key => $value) {
$expected['get'][$key] += $stackPtr;
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Utils/FunctionDeclarations/IsArrowFunctionTest.php
Expand Up @@ -128,7 +128,7 @@ public function testGetArrowFunctionOpenClose($testMarker, $expected, $targetCon
$stackPtr = $this->getTargetToken($testMarker, $targets, $targetContent);

// Change from offsets to absolute token positions.
if ($expected['get'] != false) {
if ($expected['get'] !== false) {
foreach ($expected['get'] as $key => $value) {
$expected['get'][$key] += $stackPtr;
}
Expand Down

0 comments on commit 6183442

Please sign in to comment.