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

Composer: raise the minimum supported PHPCS version to 3.10.0 #603

Merged
merged 2 commits into from
May 20, 2024
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
166 changes: 13 additions & 153 deletions PHPCSUtils/BackCompat/BCFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ final class BCFile
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 0.0.5.
* - The upstream method has received no significant updates since PHPCS 3.9.0.
* - The upstream method has received no significant updates since PHPCS 3.10.0.
*
* @see \PHP_CodeSniffer\Files\File::getDeclarationName() Original source.
* @see \PHPCSUtils\Utils\ObjectDeclarations::getName() PHPCSUtils native improved version.
Expand Down Expand Up @@ -462,7 +462,7 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr)
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 0.0.5.
* - PHPCS 3.9.2: skip over closure use statements. PHPCS #421.
* - The upstream method has received no significant updates since PHPCS 3.10.0.
*
* @see \PHP_CodeSniffer\Files\File::getMethodProperties() Original source.
* @see \PHPCSUtils\Utils\FunctionDeclarations::getProperties() PHPCSUtils native improved version.
Expand All @@ -480,147 +480,7 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr)
*/
public static function getMethodProperties(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

if ($tokens[$stackPtr]['code'] !== T_FUNCTION
&& $tokens[$stackPtr]['code'] !== T_CLOSURE
&& $tokens[$stackPtr]['code'] !== T_FN
) {
throw new RuntimeException('$stackPtr must be of type T_FUNCTION or T_CLOSURE or T_FN');
}

if ($tokens[$stackPtr]['code'] === T_FUNCTION) {
$valid = [
T_PUBLIC => T_PUBLIC,
T_PRIVATE => T_PRIVATE,
T_PROTECTED => T_PROTECTED,
T_STATIC => T_STATIC,
T_FINAL => T_FINAL,
T_ABSTRACT => T_ABSTRACT,
T_WHITESPACE => T_WHITESPACE,
T_COMMENT => T_COMMENT,
T_DOC_COMMENT => T_DOC_COMMENT,
];
} else {
$valid = [
T_STATIC => T_STATIC,
T_WHITESPACE => T_WHITESPACE,
T_COMMENT => T_COMMENT,
T_DOC_COMMENT => T_DOC_COMMENT,
];
}

$scope = 'public';
$scopeSpecified = false;
$isAbstract = false;
$isFinal = false;
$isStatic = false;

for ($i = ($stackPtr - 1); $i > 0; $i--) {
if (isset($valid[$tokens[$i]['code']]) === false) {
break;
}

switch ($tokens[$i]['code']) {
case T_PUBLIC:
$scope = 'public';
$scopeSpecified = true;
break;
case T_PRIVATE:
$scope = 'private';
$scopeSpecified = true;
break;
case T_PROTECTED:
$scope = 'protected';
$scopeSpecified = true;
break;
case T_ABSTRACT:
$isAbstract = true;
break;
case T_FINAL:
$isFinal = true;
break;
case T_STATIC:
$isStatic = true;
break;
}
}

$returnType = '';
$returnTypeToken = false;
$returnTypeEndToken = false;
$nullableReturnType = false;
$hasBody = true;
$returnTypeTokens = Collections::returnTypeTokens();

if (isset($tokens[$stackPtr]['parenthesis_closer']) === true) {
$scopeOpener = null;
if (isset($tokens[$stackPtr]['scope_opener']) === true) {
$scopeOpener = $tokens[$stackPtr]['scope_opener'];
}

for ($i = $tokens[$stackPtr]['parenthesis_closer']; $i < $phpcsFile->numTokens; $i++) {
if (($scopeOpener === null && $tokens[$i]['code'] === T_SEMICOLON)
|| ($scopeOpener !== null && $i === $scopeOpener)
) {
// End of function definition.
break;
}

if ($tokens[$i]['code'] === T_USE) {
// Skip over closure use statements.
for ($j = ($i + 1); $j < $phpcsFile->numTokens && isset(Tokens::$emptyTokens[$tokens[$j]['code']]) === true; $j++);
if ($tokens[$j]['code'] === T_OPEN_PARENTHESIS) {
if (isset($tokens[$j]['parenthesis_closer']) === false) {
// Live coding/parse error, stop parsing.
break;
}

$i = $tokens[$j]['parenthesis_closer'];
continue;
}
}

if ($tokens[$i]['code'] === T_NULLABLE) {
$nullableReturnType = true;
}

if (isset($returnTypeTokens[$tokens[$i]['code']]) === true) {
if ($returnTypeToken === false) {
$returnTypeToken = $i;
}

$returnType .= $tokens[$i]['content'];
$returnTypeEndToken = $i;
}
}

if ($tokens[$stackPtr]['code'] === T_FN) {
$bodyToken = T_FN_ARROW;
} else {
$bodyToken = T_OPEN_CURLY_BRACKET;
}

$end = $phpcsFile->findNext([$bodyToken, T_SEMICOLON], $tokens[$stackPtr]['parenthesis_closer']);
$hasBody = ($end !== false && $tokens[$end]['code'] === $bodyToken);
}

if ($returnType !== '' && $nullableReturnType === true) {
$returnType = '?' . $returnType;
}

return [
'scope' => $scope,
'scope_specified' => $scopeSpecified,
'return_type' => $returnType,
'return_type_token' => $returnTypeToken,
'return_type_end_token' => $returnTypeEndToken,
'nullable_return_type' => $nullableReturnType,
'is_abstract' => $isAbstract,
'is_final' => $isFinal,
'is_static' => $isStatic,
'has_body' => $hasBody,
];
return $phpcsFile->getMethodProperties($stackPtr);
}

/**
Expand All @@ -647,7 +507,7 @@ public static function getMethodProperties(File $phpcsFile, $stackPtr)
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 0.0.5.
* - The upstream method has received no significant updates since PHPCS 3.9.0.
* - The upstream method has received no significant updates since PHPCS 3.10.0.
*
* @see \PHP_CodeSniffer\Files\File::getMemberProperties() Original source.
* @see \PHPCSUtils\Utils\Variables::getMemberProperties() PHPCSUtils native improved version.
Expand Down Expand Up @@ -685,7 +545,7 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr)
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 1.3.0.
* - The upstream method has received no significant updates since PHPCS 3.9.0.
* - The upstream method has received no significant updates since PHPCS 3.10.0.
*
* @see \PHP_CodeSniffer\Files\File::getClassProperties() Original source.
* @see \PHPCSUtils\Utils\ObjectDeclarations::getClassProperties() PHPCSUtils native improved version.
Expand Down Expand Up @@ -713,7 +573,7 @@ public static function getClassProperties(File $phpcsFile, $stackPtr)
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 0.0.5.
* - The upstream method has received no significant updates since PHPCS 3.9.0.
* - The upstream method has received no significant updates since PHPCS 3.10.0.
*
* @see \PHP_CodeSniffer\Files\File::isReference() Original source.
* @see \PHPCSUtils\Utils\Operators::isReference() PHPCSUtils native improved version.
Expand All @@ -739,7 +599,7 @@ public static function isReference(File $phpcsFile, $stackPtr)
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 0.0.5.
* - The upstream method has received no significant updates since PHPCS 3.9.0.
* - The upstream method has received no significant updates since PHPCS 3.10.0.
*
* @see \PHP_CodeSniffer\Files\File::getTokensAsString() Original source.
* @see \PHPCSUtils\Utils\GetTokensAsString Related set of functions.
Expand Down Expand Up @@ -768,7 +628,7 @@ public static function getTokensAsString(File $phpcsFile, $start, $length, $orig
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 2.1.0.
* - The upstream method has received no significant updates since PHPCS 3.9.0.
* - The upstream method has received no significant updates since PHPCS 3.10.0.
*
* @see \PHP_CodeSniffer\Files\File::findStartOfStatement() Original source.
*
Expand All @@ -792,7 +652,7 @@ public static function findStartOfStatement(File $phpcsFile, $start, $ignore = n
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 2.1.0.
* - The upstream method has received no significant updates since PHPCS 3.9.0.
* - The upstream method has received no significant updates since PHPCS 3.10.0.
*
* @see \PHP_CodeSniffer\Files\File::findEndOfStatement() Original source.
*
Expand All @@ -816,7 +676,7 @@ public static function findEndOfStatement(File $phpcsFile, $start, $ignore = nul
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 0.0.5.
* - The upstream method has received no significant updates since PHPCS 3.9.0.
* - The upstream method has received no significant updates since PHPCS 3.10.0.
*
* @see \PHP_CodeSniffer\Files\File::hasCondition() Original source.
* @see \PHPCSUtils\Utils\Conditions::hasCondition() PHPCSUtils native alternative.
Expand All @@ -841,7 +701,7 @@ public static function hasCondition(File $phpcsFile, $stackPtr, $types)
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 1.3.0.
* - The upstream method has received no significant updates since PHPCS 3.9.0.
* - The upstream method has received no significant updates since PHPCS 3.10.0.
*
* @see \PHP_CodeSniffer\Files\File::getCondition() Original source.
* @see \PHPCSUtils\Utils\Conditions::getCondition() More versatile alternative.
Expand Down Expand Up @@ -872,7 +732,7 @@ public static function getCondition(File $phpcsFile, $stackPtr, $type, $first =
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 1.2.0.
* - The upstream method has received no significant updates since PHPCS 3.9.0.
* - The upstream method has received no significant updates since PHPCS 3.10.0.
*
* @see \PHP_CodeSniffer\Files\File::findExtendedClassName() Original source.
* @see \PHPCSUtils\Utils\ObjectDeclarations::findExtendedClassName() PHPCSUtils native improved version.
Expand All @@ -897,7 +757,7 @@ public static function findExtendedClassName(File $phpcsFile, $stackPtr)
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 2.7.0.
* - The upstream method has received no significant updates since PHPCS 3.9.0.
* - The upstream method has received no significant updates since PHPCS 3.10.0.
*
* @see \PHP_CodeSniffer\Files\File::findImplementedInterfaceNames() Original source.
* @see \PHPCSUtils\Utils\ObjectDeclarations::findImplementedInterfaceNames() PHPCSUtils native improved version.
Expand Down
2 changes: 1 addition & 1 deletion PHPCSUtils/BackCompat/BCTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ final class BCTokens

/**
* Handle calls to (undeclared) methods for token arrays which haven't received any
* changes since PHPCS 3.9.0.
* changes since PHPCS 3.10.0.
*
* @since 1.0.0
*
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Whether you need to split an `array` into the individual items, are trying to de

Includes improved versions of the PHPCS native utility functions and plenty of new utility functions.

These functions are compatible with PHPCS 3.9.0 up to PHPCS `master`.
These functions are compatible with PHPCS 3.10.0 up to PHPCS `master`.

### A collection of static properties and methods for often-used token groups

Expand All @@ -66,7 +66,7 @@ Supports PHPUnit 4.x up to 9.x.

Normally to use the latest version of PHP_CodeSniffer native utility functions, you would have to raise the minimum requirements of your external PHPCS standard.

Now you won't have to anymore. This package allows you to use the latest version of those utility functions in all PHP_CodeSniffer versions from PHPCS 3.9.0 and up.
Now you won't have to anymore. This package allows you to use the latest version of those utility functions in all PHP_CodeSniffer versions from PHPCS 3.10.0 and up.

### Fully documented

Expand All @@ -78,7 +78,7 @@ To see detailed information about all the available abstract sniffs, utility fun
## Minimum Requirements

* PHP 5.4 or higher.
* [PHP_CodeSniffer] 3.9.0+.
* [PHP_CodeSniffer] 3.10.0+.
* Recommended PHP extensions for optimal functionality:
- PCRE with Unicode support (normally enabled by default)

Expand Down
2 changes: 1 addition & 1 deletion Tests/BackCompat/Helper/GetVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testGetVersion()
}

if ($expected === 'lowest') {
$expected = '3.9.0';
$expected = '3.10.0';
}

$result = Helper::getVersion();
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"require" : {
"php" : ">=5.4",
"squizlabs/php_codesniffer" : "^3.9.0 || 4.0.x-dev@dev",
"squizlabs/php_codesniffer" : "^3.10.0 || 4.0.x-dev@dev",
"dealerdirect/phpcodesniffer-composer-installer" : "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0"
},
"require-dev" : {
Expand Down