Skip to content

Commit b3d58ca

Browse files
authored
Merge pull request #629 from PHPCSStandards/feature/tests-findstartendofstatement-sync-with-upstream
Composer: raise minimum PHPCS to 3.10.1 and sync some tests with upstream
2 parents 0c97ebf + 0644a1d commit b3d58ca

File tree

8 files changed

+410
-24
lines changed

8 files changed

+410
-24
lines changed

PHPCSUtils/BackCompat/BCFile.php

Lines changed: 12 additions & 12 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.10.0.
79+
* - The upstream method has received no significant updates since PHPCS 3.10.1.
8080
*
8181
* @see \PHP_CodeSniffer\Files\File::getDeclarationName() Original source.
8282
* @see \PHPCSUtils\Utils\ObjectDeclarations::getName() PHPCSUtils native improved version.
@@ -466,7 +466,7 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr)
466466
*
467467
* Changelog for the PHPCS native function:
468468
* - Introduced in PHPCS 0.0.5.
469-
* - The upstream method has received no significant updates since PHPCS 3.10.0.
469+
* - The upstream method has received no significant updates since PHPCS 3.10.1.
470470
*
471471
* @see \PHP_CodeSniffer\Files\File::getMethodProperties() Original source.
472472
* @see \PHPCSUtils\Utils\FunctionDeclarations::getProperties() PHPCSUtils native improved version.
@@ -511,7 +511,7 @@ public static function getMethodProperties(File $phpcsFile, $stackPtr)
511511
*
512512
* Changelog for the PHPCS native function:
513513
* - Introduced in PHPCS 0.0.5.
514-
* - The upstream method has received no significant updates since PHPCS 3.10.0.
514+
* - The upstream method has received no significant updates since PHPCS 3.10.1.
515515
*
516516
* @see \PHP_CodeSniffer\Files\File::getMemberProperties() Original source.
517517
* @see \PHPCSUtils\Utils\Variables::getMemberProperties() PHPCSUtils native improved version.
@@ -549,7 +549,7 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr)
549549
*
550550
* Changelog for the PHPCS native function:
551551
* - Introduced in PHPCS 1.3.0.
552-
* - The upstream method has received no significant updates since PHPCS 3.10.0.
552+
* - The upstream method has received no significant updates since PHPCS 3.10.1.
553553
*
554554
* @see \PHP_CodeSniffer\Files\File::getClassProperties() Original source.
555555
* @see \PHPCSUtils\Utils\ObjectDeclarations::getClassProperties() PHPCSUtils native improved version.
@@ -577,7 +577,7 @@ public static function getClassProperties(File $phpcsFile, $stackPtr)
577577
*
578578
* Changelog for the PHPCS native function:
579579
* - Introduced in PHPCS 0.0.5.
580-
* - The upstream method has received no significant updates since PHPCS 3.10.0.
580+
* - The upstream method has received no significant updates since PHPCS 3.10.1.
581581
*
582582
* @see \PHP_CodeSniffer\Files\File::isReference() Original source.
583583
* @see \PHPCSUtils\Utils\Operators::isReference() PHPCSUtils native improved version.
@@ -603,7 +603,7 @@ public static function isReference(File $phpcsFile, $stackPtr)
603603
*
604604
* Changelog for the PHPCS native function:
605605
* - Introduced in PHPCS 0.0.5.
606-
* - The upstream method has received no significant updates since PHPCS 3.10.0.
606+
* - The upstream method has received no significant updates since PHPCS 3.10.1.
607607
*
608608
* @see \PHP_CodeSniffer\Files\File::getTokensAsString() Original source.
609609
* @see \PHPCSUtils\Utils\GetTokensAsString Related set of functions.
@@ -632,7 +632,7 @@ public static function getTokensAsString(File $phpcsFile, $start, $length, $orig
632632
*
633633
* Changelog for the PHPCS native function:
634634
* - Introduced in PHPCS 2.1.0.
635-
* - The upstream method has received no significant updates since PHPCS 3.10.0.
635+
* - The upstream method has received no significant updates since PHPCS 3.10.1.
636636
*
637637
* @see \PHP_CodeSniffer\Files\File::findStartOfStatement() Original source.
638638
*
@@ -656,7 +656,7 @@ public static function findStartOfStatement(File $phpcsFile, $start, $ignore = n
656656
*
657657
* Changelog for the PHPCS native function:
658658
* - Introduced in PHPCS 2.1.0.
659-
* - The upstream method has received no significant updates since PHPCS 3.10.0.
659+
* - The upstream method has received no significant updates since PHPCS 3.10.1.
660660
*
661661
* @see \PHP_CodeSniffer\Files\File::findEndOfStatement() Original source.
662662
*
@@ -680,7 +680,7 @@ public static function findEndOfStatement(File $phpcsFile, $start, $ignore = nul
680680
*
681681
* Changelog for the PHPCS native function:
682682
* - Introduced in PHPCS 0.0.5.
683-
* - The upstream method has received no significant updates since PHPCS 3.10.0.
683+
* - The upstream method has received no significant updates since PHPCS 3.10.1.
684684
*
685685
* @see \PHP_CodeSniffer\Files\File::hasCondition() Original source.
686686
* @see \PHPCSUtils\Utils\Conditions::hasCondition() PHPCSUtils native alternative.
@@ -705,7 +705,7 @@ public static function hasCondition(File $phpcsFile, $stackPtr, $types)
705705
*
706706
* Changelog for the PHPCS native function:
707707
* - Introduced in PHPCS 1.3.0.
708-
* - The upstream method has received no significant updates since PHPCS 3.10.0.
708+
* - The upstream method has received no significant updates since PHPCS 3.10.1.
709709
*
710710
* @see \PHP_CodeSniffer\Files\File::getCondition() Original source.
711711
* @see \PHPCSUtils\Utils\Conditions::getCondition() More versatile alternative.
@@ -736,7 +736,7 @@ public static function getCondition(File $phpcsFile, $stackPtr, $type, $first =
736736
*
737737
* Changelog for the PHPCS native function:
738738
* - Introduced in PHPCS 1.2.0.
739-
* - The upstream method has received no significant updates since PHPCS 3.10.0.
739+
* - The upstream method has received no significant updates since PHPCS 3.10.1.
740740
*
741741
* @see \PHP_CodeSniffer\Files\File::findExtendedClassName() Original source.
742742
* @see \PHPCSUtils\Utils\ObjectDeclarations::findExtendedClassName() PHPCSUtils native improved version.
@@ -761,7 +761,7 @@ public static function findExtendedClassName(File $phpcsFile, $stackPtr)
761761
*
762762
* Changelog for the PHPCS native function:
763763
* - Introduced in PHPCS 2.7.0.
764-
* - The upstream method has received no significant updates since PHPCS 3.10.0.
764+
* - The upstream method has received no significant updates since PHPCS 3.10.1.
765765
*
766766
* @see \PHP_CodeSniffer\Files\File::findImplementedInterfaceNames() Original source.
767767
* @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.10.0.
77+
* changes since PHPCS 3.10.1.
7878
*
7979
* @since 1.0.0
8080
*

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Whether you need to split an `array` into the individual items, are trying to de
4646

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

49-
These functions are compatible with PHPCS 3.10.0 up to PHPCS `master`.
49+
These functions are compatible with PHPCS 3.10.1 up to PHPCS `master`.
5050

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

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

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

Tests/BackCompat/BCFile/FindEndOfStatementTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
namespace PHPCSUtils\Tests\BackCompat\BCFile;
2424

25+
use PHP_CodeSniffer\Util\Tokens;
2526
use PHPCSUtils\BackCompat\BCFile;
2627
use PHPCSUtils\TestUtils\UtilityMethodTestCase;
2728

@@ -35,6 +36,40 @@
3536
final class FindEndOfStatementTest extends UtilityMethodTestCase
3637
{
3738

39+
/**
40+
* Test that end of statement is NEVER before the "current" token.
41+
*
42+
* @return void
43+
*/
44+
public function testEndIsNeverLessThanCurrentToken()
45+
{
46+
$tokens = self::$phpcsFile->getTokens();
47+
$errors = [];
48+
49+
for ($i = 0; $i < self::$phpcsFile->numTokens; $i++) {
50+
if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === true) {
51+
continue;
52+
}
53+
54+
$end = BCFile::findEndOfStatement(self::$phpcsFile, $i);
55+
56+
// Collect all the errors.
57+
if ($end < $i) {
58+
$errors[] = sprintf(
59+
'End of statement for token %1$d (%2$s: %3$s) on line %4$d is %5$d (%6$s), which is less than %1$d',
60+
$i,
61+
$tokens[$i]['type'],
62+
$tokens[$i]['content'],
63+
$tokens[$i]['line'],
64+
$end,
65+
$tokens[$end]['type']
66+
);
67+
}
68+
}
69+
70+
$this->assertSame([], $errors);
71+
}
72+
3873
/**
3974
* Test a simple assignment.
4075
*

Tests/BackCompat/BCFile/FindStartOfStatementTest.inc

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ while(true) {}
1414
$a = 1;
1515

1616
/* testClosureAssignment */
17-
$a = function($b=false;){};
17+
$a = function($b=false){};
1818

1919
/* testHeredocFunctionArg */
2020
myFunction(<<<END
@@ -39,8 +39,8 @@ use Vendor\Package\{ClassA as A, ClassB, ClassC as C};
3939

4040
$a = [
4141
/* testArrowFunctionArrayValue */
42-
'a' => fn() => return 1,
43-
'b' => fn() => return 1,
42+
'a' => fn() => 1,
43+
'b' => fn() => 1,
4444
];
4545

4646
/* testStaticArrowFunction */
@@ -139,11 +139,11 @@ switch ($foo) {
139139
/* testInsideCaseStatement */
140140
$var = doSomething();
141141
/* testInsideCaseBreakStatement */
142-
break 2;
142+
break 1;
143143

144144
case 2:
145145
/* testInsideCaseContinueStatement */
146-
continue 2;
146+
continue 1;
147147

148148
case 3:
149149
/* testInsideCaseReturnStatement */
@@ -162,3 +162,39 @@ switch ($foo) {
162162
/* testInsideDefaultContinueStatement */
163163
continue $var;
164164
}
165+
166+
match ($var) {
167+
true =>
168+
/* test437ClosureDeclaration */
169+
function ($var) {
170+
/* test437EchoNestedWithinClosureWithinMatch */
171+
echo $var, 'text', PHP_EOL;
172+
},
173+
default => false
174+
};
175+
176+
match ($var) {
177+
/* test437NestedLongArrayWithinMatch */
178+
'a' => array( 1, 2.5, $var),
179+
/* test437NestedFunctionCallWithinMatch */
180+
'b' => functionCall( 11, $var, 50.50),
181+
/* test437NestedArrowFunctionWithinMatch */
182+
'c' => fn($p1, /* test437FnSecondParamWithinMatch */ $p2) => $p1 + $p2,
183+
default => false
184+
};
185+
186+
callMe($paramA, match ($var) {
187+
/* test437NestedLongArrayWithinNestedMatch */
188+
'a' => array( 1, 2.5, $var),
189+
/* test437NestedFunctionCallWithinNestedMatch */
190+
'b' => functionCall( 11, $var, 50.50),
191+
/* test437NestedArrowFunctionWithinNestedMatch */
192+
'c' => fn($p1, /* test437FnSecondParamWithinNestedMatch */ $p2) => $p1 + $p2,
193+
default => false
194+
});
195+
196+
match ($var) {
197+
/* test437NestedShortArrayWithinMatch */
198+
'a' => [ 1, 2.5, $var],
199+
default => false
200+
};

0 commit comments

Comments
 (0)