Skip to content

Commit 87b233b

Browse files
authored
Merge pull request #607 from PHPCSStandards/develop
Release 1.0.12
2 parents c457da9 + 60ad345 commit 87b233b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+860
-414
lines changed

CHANGELOG.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,52 @@ This projects adheres to [Keep a CHANGELOG](https://keepachangelog.com/) and use
99

1010
_Nothing yet._
1111

12+
## [1.0.12] - 2024-05-20
13+
14+
### Added
15+
16+
#### PHPCS BackCompat
17+
18+
* `BCFile::getMemberProperties()`: sync with PHPCS 3.10.0 - support for PHP 8.2 DNF types. [#604]
19+
* `BCFile::getMethodProperties()`: sync with PHPCS 3.10.0 - support for PHP 8.2 DNF types. [#604]
20+
* `BCFile::getMethodParameters()`: sync with PHPCS 3.10.0 - support for PHP 8.2 DNF types. [#604]
21+
22+
#### Utils
23+
24+
* `FunctionDeclarations::getParameters()`: support for PHP 8.2 DNF types. [#604]
25+
* `FunctionDeclarations::getProperties()`: support for PHP 8.2 DNF types. [#604]
26+
* `Variables::getMemberProperties()`: support for PHP 8.2 DNF types. [#604]
27+
28+
### Changed
29+
30+
#### Tokens
31+
32+
* `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]
33+
34+
#### Utils
35+
36+
* `ControlStructures::getCaughtExceptions()`: will now silently ignore parse errors in the code under scan which prevent the method from analyzing a `catch` statement. [#594]
37+
The method will now return an empty array instead of throwing a `PHP_CodeSniffer\Exceptions\RuntimeException`.
38+
39+
#### Other
40+
41+
* Dropped support for [PHP_CodeSniffer] < 3.10.0. [#603]
42+
Please ensure you run `composer update phpcsstandards/phpcsutils --with-dependencies` to benefit from this.
43+
* Various housekeeping and documentation improvements.
44+
45+
### Fixed
46+
47+
#### Utils
48+
49+
* `UseStatements::splitImportUseStatement()`: the values in the return array will now never include a leading backslash. [#590]
50+
Previously the behaviour around import `use` statements declared with a leading backslash was undefined and the backslash would be included in the return value.
51+
52+
[#590]: https://github.com/PHPCSStandards/PHPCSUtils/pull/590
53+
[#594]: https://github.com/PHPCSStandards/PHPCSUtils/pull/594
54+
[#603]: https://github.com/PHPCSStandards/PHPCSUtils/pull/603
55+
[#604]: https://github.com/PHPCSStandards/PHPCSUtils/pull/604
56+
57+
1258
## [1.0.11] - 2024-04-24
1359

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

10061052

10071053
[Unreleased]: https://github.com/PHPCSStandards/PHPCSUtils/compare/stable...HEAD
1054+
[1.0.12]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.11...1.0.12
10081055
[1.0.11]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.10...1.0.11
10091056
[1.0.10]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.9...1.0.10
10101057
[1.0.9]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.8...1.0.9

PHPCSUtils/BackCompat/BCFile.php

Lines changed: 18 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ final class BCFile
7676
*
7777
* Changelog for the PHPCS native function:
7878
* - Introduced in PHPCS 0.0.5.
79-
* - The upstream method has received no significant updates since PHPCS 3.9.0.
79+
* - The upstream method has received no significant updates since PHPCS 3.10.0.
8080
*
8181
* @see \PHP_CodeSniffer\Files\File::getDeclarationName() Original source.
8282
* @see \PHPCSUtils\Utils\ObjectDeclarations::getName() PHPCSUtils native improved version.
@@ -228,7 +228,9 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr)
228228
// it's likely to be an array which might have arguments in it. This
229229
// could cause problems in our parsing below, so lets just skip to the
230230
// end of it.
231-
if (isset($tokens[$i]['parenthesis_opener']) === true) {
231+
if ($tokens[$i]['code'] !== T_TYPE_OPEN_PARENTHESIS
232+
&& isset($tokens[$i]['parenthesis_opener']) === true
233+
) {
232234
// Don't do this if it's the close parenthesis for the method.
233235
if ($i !== $tokens[$i]['parenthesis_closer']) {
234236
$i = ($tokens[$i]['parenthesis_closer'] + 1);
@@ -324,6 +326,8 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr)
324326
case T_NS_SEPARATOR:
325327
case T_TYPE_UNION:
326328
case T_TYPE_INTERSECTION:
329+
case T_TYPE_OPEN_PARENTHESIS:
330+
case T_TYPE_CLOSE_PARENTHESIS:
327331
case T_FALSE:
328332
case T_TRUE:
329333
case T_NULL:
@@ -462,7 +466,7 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr)
462466
*
463467
* Changelog for the PHPCS native function:
464468
* - Introduced in PHPCS 0.0.5.
465-
* - PHPCS 3.9.2: skip over closure use statements. PHPCS #421.
469+
* - The upstream method has received no significant updates since PHPCS 3.10.0.
466470
*
467471
* @see \PHP_CodeSniffer\Files\File::getMethodProperties() Original source.
468472
* @see \PHPCSUtils\Utils\FunctionDeclarations::getProperties() PHPCSUtils native improved version.
@@ -480,147 +484,7 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr)
480484
*/
481485
public static function getMethodProperties(File $phpcsFile, $stackPtr)
482486
{
483-
$tokens = $phpcsFile->getTokens();
484-
485-
if ($tokens[$stackPtr]['code'] !== T_FUNCTION
486-
&& $tokens[$stackPtr]['code'] !== T_CLOSURE
487-
&& $tokens[$stackPtr]['code'] !== T_FN
488-
) {
489-
throw new RuntimeException('$stackPtr must be of type T_FUNCTION or T_CLOSURE or T_FN');
490-
}
491-
492-
if ($tokens[$stackPtr]['code'] === T_FUNCTION) {
493-
$valid = [
494-
T_PUBLIC => T_PUBLIC,
495-
T_PRIVATE => T_PRIVATE,
496-
T_PROTECTED => T_PROTECTED,
497-
T_STATIC => T_STATIC,
498-
T_FINAL => T_FINAL,
499-
T_ABSTRACT => T_ABSTRACT,
500-
T_WHITESPACE => T_WHITESPACE,
501-
T_COMMENT => T_COMMENT,
502-
T_DOC_COMMENT => T_DOC_COMMENT,
503-
];
504-
} else {
505-
$valid = [
506-
T_STATIC => T_STATIC,
507-
T_WHITESPACE => T_WHITESPACE,
508-
T_COMMENT => T_COMMENT,
509-
T_DOC_COMMENT => T_DOC_COMMENT,
510-
];
511-
}
512-
513-
$scope = 'public';
514-
$scopeSpecified = false;
515-
$isAbstract = false;
516-
$isFinal = false;
517-
$isStatic = false;
518-
519-
for ($i = ($stackPtr - 1); $i > 0; $i--) {
520-
if (isset($valid[$tokens[$i]['code']]) === false) {
521-
break;
522-
}
523-
524-
switch ($tokens[$i]['code']) {
525-
case T_PUBLIC:
526-
$scope = 'public';
527-
$scopeSpecified = true;
528-
break;
529-
case T_PRIVATE:
530-
$scope = 'private';
531-
$scopeSpecified = true;
532-
break;
533-
case T_PROTECTED:
534-
$scope = 'protected';
535-
$scopeSpecified = true;
536-
break;
537-
case T_ABSTRACT:
538-
$isAbstract = true;
539-
break;
540-
case T_FINAL:
541-
$isFinal = true;
542-
break;
543-
case T_STATIC:
544-
$isStatic = true;
545-
break;
546-
}
547-
}
548-
549-
$returnType = '';
550-
$returnTypeToken = false;
551-
$returnTypeEndToken = false;
552-
$nullableReturnType = false;
553-
$hasBody = true;
554-
$returnTypeTokens = Collections::returnTypeTokens();
555-
556-
if (isset($tokens[$stackPtr]['parenthesis_closer']) === true) {
557-
$scopeOpener = null;
558-
if (isset($tokens[$stackPtr]['scope_opener']) === true) {
559-
$scopeOpener = $tokens[$stackPtr]['scope_opener'];
560-
}
561-
562-
for ($i = $tokens[$stackPtr]['parenthesis_closer']; $i < $phpcsFile->numTokens; $i++) {
563-
if (($scopeOpener === null && $tokens[$i]['code'] === T_SEMICOLON)
564-
|| ($scopeOpener !== null && $i === $scopeOpener)
565-
) {
566-
// End of function definition.
567-
break;
568-
}
569-
570-
if ($tokens[$i]['code'] === T_USE) {
571-
// Skip over closure use statements.
572-
for ($j = ($i + 1); $j < $phpcsFile->numTokens && isset(Tokens::$emptyTokens[$tokens[$j]['code']]) === true; $j++);
573-
if ($tokens[$j]['code'] === T_OPEN_PARENTHESIS) {
574-
if (isset($tokens[$j]['parenthesis_closer']) === false) {
575-
// Live coding/parse error, stop parsing.
576-
break;
577-
}
578-
579-
$i = $tokens[$j]['parenthesis_closer'];
580-
continue;
581-
}
582-
}
583-
584-
if ($tokens[$i]['code'] === T_NULLABLE) {
585-
$nullableReturnType = true;
586-
}
587-
588-
if (isset($returnTypeTokens[$tokens[$i]['code']]) === true) {
589-
if ($returnTypeToken === false) {
590-
$returnTypeToken = $i;
591-
}
592-
593-
$returnType .= $tokens[$i]['content'];
594-
$returnTypeEndToken = $i;
595-
}
596-
}
597-
598-
if ($tokens[$stackPtr]['code'] === T_FN) {
599-
$bodyToken = T_FN_ARROW;
600-
} else {
601-
$bodyToken = T_OPEN_CURLY_BRACKET;
602-
}
603-
604-
$end = $phpcsFile->findNext([$bodyToken, T_SEMICOLON], $tokens[$stackPtr]['parenthesis_closer']);
605-
$hasBody = ($end !== false && $tokens[$end]['code'] === $bodyToken);
606-
}
607-
608-
if ($returnType !== '' && $nullableReturnType === true) {
609-
$returnType = '?' . $returnType;
610-
}
611-
612-
return [
613-
'scope' => $scope,
614-
'scope_specified' => $scopeSpecified,
615-
'return_type' => $returnType,
616-
'return_type_token' => $returnTypeToken,
617-
'return_type_end_token' => $returnTypeEndToken,
618-
'nullable_return_type' => $nullableReturnType,
619-
'is_abstract' => $isAbstract,
620-
'is_final' => $isFinal,
621-
'is_static' => $isStatic,
622-
'has_body' => $hasBody,
623-
];
487+
return $phpcsFile->getMethodProperties($stackPtr);
624488
}
625489

626490
/**
@@ -647,7 +511,7 @@ public static function getMethodProperties(File $phpcsFile, $stackPtr)
647511
*
648512
* Changelog for the PHPCS native function:
649513
* - Introduced in PHPCS 0.0.5.
650-
* - The upstream method has received no significant updates since PHPCS 3.9.0.
514+
* - The upstream method has received no significant updates since PHPCS 3.10.0.
651515
*
652516
* @see \PHP_CodeSniffer\Files\File::getMemberProperties() Original source.
653517
* @see \PHPCSUtils\Utils\Variables::getMemberProperties() PHPCSUtils native improved version.
@@ -685,7 +549,7 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr)
685549
*
686550
* Changelog for the PHPCS native function:
687551
* - Introduced in PHPCS 1.3.0.
688-
* - The upstream method has received no significant updates since PHPCS 3.9.0.
552+
* - The upstream method has received no significant updates since PHPCS 3.10.0.
689553
*
690554
* @see \PHP_CodeSniffer\Files\File::getClassProperties() Original source.
691555
* @see \PHPCSUtils\Utils\ObjectDeclarations::getClassProperties() PHPCSUtils native improved version.
@@ -713,7 +577,7 @@ public static function getClassProperties(File $phpcsFile, $stackPtr)
713577
*
714578
* Changelog for the PHPCS native function:
715579
* - Introduced in PHPCS 0.0.5.
716-
* - The upstream method has received no significant updates since PHPCS 3.9.0.
580+
* - The upstream method has received no significant updates since PHPCS 3.10.0.
717581
*
718582
* @see \PHP_CodeSniffer\Files\File::isReference() Original source.
719583
* @see \PHPCSUtils\Utils\Operators::isReference() PHPCSUtils native improved version.
@@ -739,7 +603,7 @@ public static function isReference(File $phpcsFile, $stackPtr)
739603
*
740604
* Changelog for the PHPCS native function:
741605
* - Introduced in PHPCS 0.0.5.
742-
* - The upstream method has received no significant updates since PHPCS 3.9.0.
606+
* - The upstream method has received no significant updates since PHPCS 3.10.0.
743607
*
744608
* @see \PHP_CodeSniffer\Files\File::getTokensAsString() Original source.
745609
* @see \PHPCSUtils\Utils\GetTokensAsString Related set of functions.
@@ -768,7 +632,7 @@ public static function getTokensAsString(File $phpcsFile, $start, $length, $orig
768632
*
769633
* Changelog for the PHPCS native function:
770634
* - Introduced in PHPCS 2.1.0.
771-
* - The upstream method has received no significant updates since PHPCS 3.9.0.
635+
* - The upstream method has received no significant updates since PHPCS 3.10.0.
772636
*
773637
* @see \PHP_CodeSniffer\Files\File::findStartOfStatement() Original source.
774638
*
@@ -792,7 +656,7 @@ public static function findStartOfStatement(File $phpcsFile, $start, $ignore = n
792656
*
793657
* Changelog for the PHPCS native function:
794658
* - Introduced in PHPCS 2.1.0.
795-
* - The upstream method has received no significant updates since PHPCS 3.9.0.
659+
* - The upstream method has received no significant updates since PHPCS 3.10.0.
796660
*
797661
* @see \PHP_CodeSniffer\Files\File::findEndOfStatement() Original source.
798662
*
@@ -816,7 +680,7 @@ public static function findEndOfStatement(File $phpcsFile, $start, $ignore = nul
816680
*
817681
* Changelog for the PHPCS native function:
818682
* - Introduced in PHPCS 0.0.5.
819-
* - The upstream method has received no significant updates since PHPCS 3.9.0.
683+
* - The upstream method has received no significant updates since PHPCS 3.10.0.
820684
*
821685
* @see \PHP_CodeSniffer\Files\File::hasCondition() Original source.
822686
* @see \PHPCSUtils\Utils\Conditions::hasCondition() PHPCSUtils native alternative.
@@ -841,7 +705,7 @@ public static function hasCondition(File $phpcsFile, $stackPtr, $types)
841705
*
842706
* Changelog for the PHPCS native function:
843707
* - Introduced in PHPCS 1.3.0.
844-
* - The upstream method has received no significant updates since PHPCS 3.9.0.
708+
* - The upstream method has received no significant updates since PHPCS 3.10.0.
845709
*
846710
* @see \PHP_CodeSniffer\Files\File::getCondition() Original source.
847711
* @see \PHPCSUtils\Utils\Conditions::getCondition() More versatile alternative.
@@ -872,7 +736,7 @@ public static function getCondition(File $phpcsFile, $stackPtr, $type, $first =
872736
*
873737
* Changelog for the PHPCS native function:
874738
* - Introduced in PHPCS 1.2.0.
875-
* - The upstream method has received no significant updates since PHPCS 3.9.0.
739+
* - The upstream method has received no significant updates since PHPCS 3.10.0.
876740
*
877741
* @see \PHP_CodeSniffer\Files\File::findExtendedClassName() Original source.
878742
* @see \PHPCSUtils\Utils\ObjectDeclarations::findExtendedClassName() PHPCSUtils native improved version.
@@ -897,7 +761,7 @@ public static function findExtendedClassName(File $phpcsFile, $stackPtr)
897761
*
898762
* Changelog for the PHPCS native function:
899763
* - Introduced in PHPCS 2.7.0.
900-
* - The upstream method has received no significant updates since PHPCS 3.9.0.
764+
* - The upstream method has received no significant updates since PHPCS 3.10.0.
901765
*
902766
* @see \PHP_CodeSniffer\Files\File::findImplementedInterfaceNames() Original source.
903767
* @see \PHPCSUtils\Utils\ObjectDeclarations::findImplementedInterfaceNames() PHPCSUtils native improved version.

PHPCSUtils/BackCompat/BCTokens.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ final class BCTokens
7474

7575
/**
7676
* Handle calls to (undeclared) methods for token arrays which haven't received any
77-
* changes since PHPCS 3.9.0.
77+
* changes since PHPCS 3.10.0.
7878
*
7979
* @since 1.0.0
8080
*

PHPCSUtils/TestUtils/UtilityMethodTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
* *
8585
* * @return array
8686
* * /
87-
* public function dataMyMethod()
87+
* public static function dataMyMethod()
8888
* {
8989
* return array(
9090
* array('/* testTestCaseDescription * /', false),

0 commit comments

Comments
 (0)