Skip to content

Commit

Permalink
Merge pull request #607 from PHPCSStandards/develop
Browse files Browse the repository at this point in the history
Release 1.0.12
  • Loading branch information
jrfnl committed May 20, 2024
2 parents c457da9 + 60ad345 commit 87b233b
Show file tree
Hide file tree
Showing 45 changed files with 860 additions and 414 deletions.
47 changes: 47 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,52 @@ This projects adheres to [Keep a CHANGELOG](https://keepachangelog.com/) and use

_Nothing yet._

## [1.0.12] - 2024-05-20

### Added

#### PHPCS BackCompat

* `BCFile::getMemberProperties()`: sync with PHPCS 3.10.0 - support for PHP 8.2 DNF types. [#604]
* `BCFile::getMethodProperties()`: sync with PHPCS 3.10.0 - support for PHP 8.2 DNF types. [#604]
* `BCFile::getMethodParameters()`: sync with PHPCS 3.10.0 - support for PHP 8.2 DNF types. [#604]

#### Utils

* `FunctionDeclarations::getParameters()`: support for PHP 8.2 DNF types. [#604]
* `FunctionDeclarations::getProperties()`: support for PHP 8.2 DNF types. [#604]
* `Variables::getMemberProperties()`: support for PHP 8.2 DNF types. [#604]

### Changed

#### Tokens

* `Collections::parameterTypeTokens()`, `Collections::propertyTypeTokens()` and `Collections::returnTypeTokens()`: now include the new `T_TYPE_OPEN_PARENTHESIS` and `T_TYPE_CLOSE_PARENTHESIS` tokens for PHP 8.2 DNF type support. [#604]

#### Utils

* `ControlStructures::getCaughtExceptions()`: will now silently ignore parse errors in the code under scan which prevent the method from analyzing a `catch` statement. [#594]
The method will now return an empty array instead of throwing a `PHP_CodeSniffer\Exceptions\RuntimeException`.

#### Other

* Dropped support for [PHP_CodeSniffer] < 3.10.0. [#603]
Please ensure you run `composer update phpcsstandards/phpcsutils --with-dependencies` to benefit from this.
* Various housekeeping and documentation improvements.

### Fixed

#### Utils

* `UseStatements::splitImportUseStatement()`: the values in the return array will now never include a leading backslash. [#590]
Previously the behaviour around import `use` statements declared with a leading backslash was undefined and the backslash would be included in the return value.

[#590]: https://github.com/PHPCSStandards/PHPCSUtils/pull/590
[#594]: https://github.com/PHPCSStandards/PHPCSUtils/pull/594
[#603]: https://github.com/PHPCSStandards/PHPCSUtils/pull/603
[#604]: https://github.com/PHPCSStandards/PHPCSUtils/pull/604


## [1.0.11] - 2024-04-24

### Changed
Expand Down Expand Up @@ -1005,6 +1051,7 @@ This initial alpha release contains the following utility classes:


[Unreleased]: https://github.com/PHPCSStandards/PHPCSUtils/compare/stable...HEAD
[1.0.12]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.11...1.0.12
[1.0.11]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.10...1.0.11
[1.0.10]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.9...1.0.10
[1.0.9]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.8...1.0.9
Expand Down
172 changes: 18 additions & 154 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 @@ -228,7 +228,9 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr)
// it's likely to be an array which might have arguments in it. This
// could cause problems in our parsing below, so lets just skip to the
// end of it.
if (isset($tokens[$i]['parenthesis_opener']) === true) {
if ($tokens[$i]['code'] !== T_TYPE_OPEN_PARENTHESIS
&& isset($tokens[$i]['parenthesis_opener']) === true
) {
// Don't do this if it's the close parenthesis for the method.
if ($i !== $tokens[$i]['parenthesis_closer']) {
$i = ($tokens[$i]['parenthesis_closer'] + 1);
Expand Down Expand Up @@ -324,6 +326,8 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr)
case T_NS_SEPARATOR:
case T_TYPE_UNION:
case T_TYPE_INTERSECTION:
case T_TYPE_OPEN_PARENTHESIS:
case T_TYPE_CLOSE_PARENTHESIS:
case T_FALSE:
case T_TRUE:
case T_NULL:
Expand Down Expand Up @@ -462,7 +466,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 +484,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 +511,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 +549,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 +577,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 +603,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 +632,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 +656,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 +680,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 +705,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 +736,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 +761,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
2 changes: 1 addition & 1 deletion PHPCSUtils/TestUtils/UtilityMethodTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
* *
* * @return array
* * /
* public function dataMyMethod()
* public static function dataMyMethod()
* {
* return array(
* array('/* testTestCaseDescription * /', false),
Expand Down
Loading

0 comments on commit 87b233b

Please sign in to comment.