Skip to content

Commit

Permalink
Raise PHP CodeSniffer from 3.10.3 to 3.11.1
Browse files Browse the repository at this point in the history
Update AssignmentInReturnSniff for the BC break in
PHPCSStandards/PHP_CodeSniffer#647.

Bug: T379674
Change-Id: I01009b858466b7c678c799d8c99207f3395b7a5d
  • Loading branch information
jdforrester authored and Daimona committed Jan 12, 2025
1 parent 9479c6b commit 3a61696
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
23 changes: 18 additions & 5 deletions MediaWiki/Sniffs/Usage/AssignmentInReturnSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,25 @@ public function process( File $phpcsFile, $stackPtr ) {
&& $code !== T_DOUBLE_ARROW
) {
$errorPtr = $stackPtr;
// "yield from" could be multiline, get content from more than one token
$content = '';
do {
$content .= $tokens[$stackPtr]['content'];
$content = $tokens[$stackPtr]['content'];
// "yield from" could have whitespace and comments in the middle. If we only got a `yield`, skip
// forwards until we find the `from`. See https://github.com/PHPCSStandards/PHP_CodeSniffer/pull/647
if ( $tokens[$stackPtr]['code'] === T_YIELD_FROM && $content === 'yield' ) {
$nextNotNoop = $phpcsFile->findNext( [ T_COMMENT, T_WHITESPACE ], $stackPtr + 1, null, true );
if (
$nextNotNoop === false ||
$tokens[$nextNotNoop]['code'] !== T_YIELD_FROM ||
$tokens[$nextNotNoop]['content'] !== 'from'
) {
// Should never happen.
$stackPtr++;
} else {
$content .= ' from';
$stackPtr = $nextNotNoop + 1;
}
} else {
$stackPtr++;
} while ( $tokens[$stackPtr]['code'] === T_YIELD_FROM );
}
// Split by any whitespaces and build better looking content with one space
$contentPieces = preg_split( '/\s+/', $content );
$phpcsFile->addError(
Expand Down
3 changes: 2 additions & 1 deletion MediaWiki/Tests/files/Usage/assignment_in_return.php.expect
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
33 | ERROR | [ ] Assignment expression not allowed within "yield from".
| | (MediaWiki.Usage.AssignmentInReturn.AssignmentInYieldFrom)
33 | ERROR | [x] Language constructs must be followed by a single space; expected 1 space between
| | YIELD FROM found "yield\n\t\tfrom"
| | YIELD FROM found
| | "yield\n········from"
| | (Generic.WhiteSpace.LanguageConstructSpacing.IncorrectYieldFrom)
35 | ERROR | [ ] Assignment expression not allowed within "yield from".
| | (MediaWiki.Usage.AssignmentInReturn.AssignmentInYieldFrom)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"ext-mbstring": "*",
"composer/semver": "3.4.2 || 3.4.3",
"composer/spdx-licenses": "~1.5.2",
"squizlabs/php_codesniffer": "3.10.3",
"squizlabs/php_codesniffer": "3.11.1",
"symfony/polyfill-php80": "^1.26.0",
"phpcsstandards/phpcsextra": "1.2.1"
},
Expand Down

0 comments on commit 3a61696

Please sign in to comment.