Skip to content

Commit 5f9967d

Browse files
committed
Merge branch '2.16' into 2.17
# Conflicts: # src/Console/Application.php
2 parents 8c61e03 + 1ff5457 commit 5f9967d

File tree

8 files changed

+100
-29
lines changed

8 files changed

+100
-29
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ insert_final_newline = true
55
indent_style = space
66
indent_size = 4
77
trim_trailing_whitespace = true
8+
9+
[*.yml]
10+
indent_size = 2

.github/workflows/ci.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ jobs:
8686
composer-
8787
8888
- name: Configure Symfony Flex
89-
run: |
90-
composer config extra.symfony.require ${{ matrix.execute-flex-with-symfony-version }}
89+
run: composer config extra.symfony.require ${{ matrix.execute-flex-with-symfony-version }}
9190
if: "matrix.execute-flex-with-symfony-version"
9291

9392
- name: Install dependencies
@@ -98,11 +97,10 @@ jobs:
9897
retry_wait_seconds: 30
9998
command: |
10099
composer update --optimize-autoloader --no-interaction --no-progress ${{ matrix.composer-flags }}
101-
composer info -D | sort
100+
composer info -D
102101
103102
- name: Execute migration rules
104-
run: |
105-
php php-cs-fixer fix --rules @PHP73Migration,@PHP71Migration:risky,blank_line_after_opening_tag -q
103+
run: php php-cs-fixer fix --rules @PHP73Migration,@PHP71Migration:risky,blank_line_after_opening_tag -q
106104
if: "matrix.execute-migration-rules == 'yes'"
107105

108106
- name: Run tests
@@ -112,12 +110,10 @@ jobs:
112110
FAST_LINT_TEST_CASES: ${{ matrix.FAST_LINT_TEST_CASES }}
113111
PHP_CS_FIXER_TEST_USE_LEGACY_TOKENIZER: ${{ matrix.PHP_CS_FIXER_TEST_USE_LEGACY_TOKENIZER }}
114112
SYMFONY_DEPRECATIONS_HELPER: ${{ matrix.SYMFONY_DEPRECATIONS_HELPER }}
115-
run: |
116-
vendor/bin/phpunit
113+
run: vendor/bin/phpunit
117114

118115
- name: Run PHP CS Fixer
119116
env:
120117
PHP_CS_FIXER_IGNORE_ENV: ${{ matrix.PHP_CS_FIXER_IGNORE_ENV }}
121118
PHP_CS_FIXER_FUTURE_MODE: 1
122-
run: |
123-
php php-cs-fixer --diff --dry-run -v fix
119+
run: php php-cs-fixer --diff --dry-run -v fix

.github/workflows/sca.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,18 @@ jobs:
4949
timeout_minutes: 5
5050
max_attempts: 5
5151
retry_wait_seconds: 30
52-
command: |
53-
composer update --optimize-autoloader --no-interaction --no-progress ${{ matrix.composer-flags }}
52+
command: composer update --optimize-autoloader --no-interaction --no-progress ${{ matrix.composer-flags }}
5453

5554
- name: Report versions
56-
run: |
57-
composer info -D
55+
run: composer info -D
5856

5957
- name: Install dev-tools
6058
uses: nick-invision/retry@v2
6159
with:
6260
timeout_minutes: 5
6361
max_attempts: 5
6462
retry_wait_seconds: 30
65-
command: |
66-
./dev-tools/install.sh
63+
command: ./dev-tools/install.sh
6764

6865
- name: Run checks
6966
run: |
@@ -92,8 +89,7 @@ jobs:
9289
9390
- name: Validate changed files
9491
if: ${{ github.env.CHANGED_PHP_FILES }}
95-
run: |
96-
./dev-tools/vendor/bin/phpmd `echo "$CHANGED_PHP_FILES" | xargs | sed 's/ /,/g'` text phpmd.xml
92+
run: ./dev-tools/vendor/bin/phpmd `echo "$CHANGED_PHP_FILES" | xargs | sed 's/ /,/g'` text phpmd.xml
9793

9894
- name: Check for unknown files (to be removed in 3.0)
9995
run: |

.github/workflows/yaml.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ jobs:
1818
uses: actions/checkout@v2
1919

2020
- name: Run yamllint
21-
run: |
22-
find . -path \*/vendor -prune -false -o -name \*.y*ml | xargs yamllint
21+
run: find . -path \*/vendor -prune -false -o -name \*.y*ml | xargs yamllint

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ Changelog for v2.17.0
7272
Changelog for v2.16.8
7373
---------------------
7474

75+
* bug #5325 NoBreakCommentFixer - better throw handling (SpacePossum)
76+
* bug #5327 StaticLambdaFixer - fix for arrow function used in class with $this (kubawerlos, SpacePossum)
77+
* bug #5333 Fix file missing for php8 (jderusse)
78+
* minor #5328 Fixed deprecation message version (GrahamCampbell)
79+
* minor #5330 DX: cleanup Github Actions configs (kubawerlos)
80+
81+
Changelog for v2.16.9
82+
---------------------
83+
7584
* bug #5095 Annotation - fix for Windows line endings (SpacePossum)
7685
* bug #5221 NoSuperfluousPhpdocTagsFixer - fix for single line PHPDoc (kubawerlos)
7786
* bug #5225 TernaryOperatorSpacesFixer - fix for alternative control structures (kubawerlos)

src/Console/ConfigurationResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ private function validateRules(array $rules)
783783
if (isset($rules[$fixerName]) && $fixer instanceof DeprecatedFixerInterface) {
784784
$successors = $fixer->getSuccessorsNames();
785785
$messageEnd = [] === $successors
786-
? sprintf(' and will be removed in version %d.0.', Application::getMajorVersion())
786+
? sprintf(' and will be removed in version %d.0.', Application::getMajorVersion() + 1)
787787
: sprintf('. Use %s instead.', str_replace('`', '"', Utils::naturalLanguageJoinWithBackticks($successors)));
788788

789789
$message = "Rule \"{$fixerName}\" is deprecated{$messageEnd}";

src/Fixer/FunctionNotation/StaticLambdaFixer.php

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ public function isRisky()
6464
protected function applyFix(\SplFileInfo $file, Tokens $tokens)
6565
{
6666
$analyzer = new TokensAnalyzer($tokens);
67-
6867
$expectedFunctionKinds = [T_FUNCTION];
68+
6969
if (\PHP_VERSION_ID >= 70400) {
7070
$expectedFunctionKinds[] = T_FN;
7171
}
@@ -76,21 +76,22 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
7676
}
7777

7878
$prev = $tokens->getPrevMeaningfulToken($index);
79+
7980
if ($tokens[$prev]->isGivenKind(T_STATIC)) {
8081
continue; // lambda is already 'static'
8182
}
8283

8384
$argumentsStartIndex = $tokens->getNextTokenOfKind($index, ['(']);
8485
$argumentsEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $argumentsStartIndex);
8586

86-
// figure out where the lambda starts ...
87-
$lambdaOpenIndex = $tokens->getNextTokenOfKind($argumentsEndIndex, ['{', [T_DOUBLE_ARROW]]);
87+
// figure out where the lambda starts and ends
8888

89-
// ... and where it ends
90-
if ($tokens[$lambdaOpenIndex]->isGivenKind(T_DOUBLE_ARROW)) {
91-
$lambdaEndIndex = $tokens->getNextTokenOfKind($lambdaOpenIndex, [';']);
92-
} else {
89+
if ($tokens[$index]->isGivenKind(T_FUNCTION)) {
90+
$lambdaOpenIndex = $tokens->getNextTokenOfKind($argumentsEndIndex, ['{']);
9391
$lambdaEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $lambdaOpenIndex);
92+
} else { // T_FN
93+
$lambdaOpenIndex = $tokens->getNextTokenOfKind($argumentsEndIndex, [[T_DOUBLE_ARROW]]);
94+
$lambdaEndIndex = $this->findExpressionEnd($tokens, $lambdaOpenIndex);
9495
}
9596

9697
if ($this->hasPossibleReferenceToThis($tokens, $lambdaOpenIndex, $lambdaEndIndex)) {
@@ -110,6 +111,37 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
110111
}
111112
}
112113

114+
/**
115+
* @param int $index
116+
*
117+
* @return int
118+
*/
119+
private function findExpressionEnd(Tokens $tokens, $index)
120+
{
121+
$nextIndex = $tokens->getNextMeaningfulToken($index);
122+
123+
while (null !== $nextIndex) {
124+
/** @var Token $nextToken */
125+
$nextToken = $tokens[$nextIndex];
126+
127+
if ($nextToken->equalsAny([',', ';', [T_CLOSE_TAG]])) {
128+
break;
129+
}
130+
131+
/** @var null|array{isStart: bool, type: int} $blockType */
132+
$blockType = Tokens::detectBlockType($nextToken);
133+
134+
if (null !== $blockType && $blockType['isStart']) {
135+
$nextIndex = $tokens->findBlockEnd($blockType['type'], $nextIndex);
136+
}
137+
138+
$index = $nextIndex;
139+
$nextIndex = $tokens->getNextMeaningfulToken($index);
140+
}
141+
142+
return $index;
143+
}
144+
113145
/**
114146
* Returns 'true' if there is a possible reference to '$this' within the given tokens index range.
115147
*
@@ -138,6 +170,7 @@ private function hasPossibleReferenceToThis(Tokens $tokens, $startIndex, $endInd
138170

139171
if ($tokens[$i]->equals('$')) {
140172
$nextIndex = $tokens->getNextMeaningfulToken($i);
173+
141174
if ($tokens[$nextIndex]->isGivenKind(T_VARIABLE)) {
142175
return true; // "$$a" case
143176
}

tests/Fixer/FunctionNotation/StaticLambdaFixerTest.php

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,12 @@ public function provideFixPhp74Cases()
258258
'<?php $a /**/ = /**/ fn() => null;',
259259
],
260260
[
261-
'<?php $a /**/ = /**/static fn() => null;',
262-
'<?php $a /**/ = /**/fn() => null;',
261+
'<?php $a /**/ = /**/static fn() => null; echo $this->foo();',
262+
'<?php $a /**/ = /**/fn() => null; echo $this->foo();',
263+
],
264+
[
265+
'<?php $a /**/ = /**/ static fn() => null ?> <?php echo $this->foo();',
266+
'<?php $a /**/ = /**/ fn() => null ?> <?php echo $this->foo();',
263267
],
264268
[
265269
'<?php
@@ -277,6 +281,37 @@ public function C()
277281
'<?php static fn($a = ["foo" => "bar"]) => [];',
278282
'<?php fn($a = ["foo" => "bar"]) => [];',
279283
],
284+
[
285+
'<?php class Foo {
286+
public function getNames()
287+
{
288+
return \array_map(
289+
static fn ($item) => $item->getName(),
290+
$this->getItems()
291+
);
292+
}
293+
}',
294+
'<?php class Foo {
295+
public function getNames()
296+
{
297+
return \array_map(
298+
fn ($item) => $item->getName(),
299+
$this->getItems()
300+
);
301+
}
302+
}',
303+
],
304+
[
305+
'<?php class Foo {
306+
public function getNames()
307+
{
308+
return \array_map(
309+
fn ($item) => $item->getName(1, $this->foo()),
310+
$this->getItems()
311+
);
312+
}
313+
}',
314+
],
280315
];
281316
}
282317
}

0 commit comments

Comments
 (0)