Skip to content

Commit

Permalink
Merge branch '2.17'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Console/Application.php
  • Loading branch information
keradus committed Dec 8, 2020
2 parents 9b0ccd1 + 563945b commit b9f8f8e
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.yml]
indent_size = 2
14 changes: 5 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ jobs:
composer-
- name: Configure Symfony Flex
run: |
composer config extra.symfony.require ${{ matrix.execute-flex-with-symfony-version }}
run: composer config extra.symfony.require ${{ matrix.execute-flex-with-symfony-version }}
if: "matrix.execute-flex-with-symfony-version"

- name: Install dependencies
Expand All @@ -98,11 +97,10 @@ jobs:
retry_wait_seconds: 30
command: |
composer update --optimize-autoloader --no-interaction --no-progress ${{ matrix.composer-flags }}
composer info -D | sort
composer info -D
- name: Execute migration rules
run: |
php php-cs-fixer fix --rules @PHP73Migration,@PHP71Migration:risky,blank_line_after_opening_tag -q
run: php php-cs-fixer fix --rules @PHP73Migration,@PHP71Migration:risky,blank_line_after_opening_tag -q
if: "matrix.execute-migration-rules == 'yes'"

- name: Run tests
Expand All @@ -112,12 +110,10 @@ jobs:
FAST_LINT_TEST_CASES: ${{ matrix.FAST_LINT_TEST_CASES }}
PHP_CS_FIXER_TEST_USE_LEGACY_TOKENIZER: ${{ matrix.PHP_CS_FIXER_TEST_USE_LEGACY_TOKENIZER }}
SYMFONY_DEPRECATIONS_HELPER: ${{ matrix.SYMFONY_DEPRECATIONS_HELPER }}
run: |
vendor/bin/phpunit
run: vendor/bin/phpunit

- name: Run PHP CS Fixer
env:
PHP_CS_FIXER_IGNORE_ENV: ${{ matrix.PHP_CS_FIXER_IGNORE_ENV }}
PHP_CS_FIXER_FUTURE_MODE: 1
run: |
php php-cs-fixer --diff --dry-run -v fix
run: php php-cs-fixer --diff --dry-run -v fix
12 changes: 4 additions & 8 deletions .github/workflows/sca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,18 @@ jobs:
timeout_minutes: 5
max_attempts: 5
retry_wait_seconds: 30
command: |
composer update --optimize-autoloader --no-interaction --no-progress ${{ matrix.composer-flags }}
command: composer update --optimize-autoloader --no-interaction --no-progress ${{ matrix.composer-flags }}

- name: Report versions
run: |
composer info -D
run: composer info -D

- name: Install dev-tools
uses: nick-invision/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
retry_wait_seconds: 30
command: |
./dev-tools/install.sh
command: ./dev-tools/install.sh

- name: Run checks
run: |
Expand Down Expand Up @@ -92,8 +89,7 @@ jobs:
- name: Validate changed files
if: ${{ github.env.CHANGED_PHP_FILES }}
run: |
./dev-tools/vendor/bin/phpmd `echo "$CHANGED_PHP_FILES" | xargs | sed 's/ /,/g'` text phpmd.xml
run: ./dev-tools/vendor/bin/phpmd `echo "$CHANGED_PHP_FILES" | xargs | sed 's/ /,/g'` text phpmd.xml

- name: Check for unknown files (to be removed in 3.0)
run: |
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/yaml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ jobs:
uses: actions/checkout@v2

- name: Run yamllint
run: |
find . -path \*/vendor -prune -false -o -name \*.y*ml | xargs yamllint
run: find . -path \*/vendor -prune -false -o -name \*.y*ml | xargs yamllint
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ CHANGELOG for PHP CS Fixer

This file contains changelogs for stable releases only.

Changelog for v2.17.1
---------------------

* bug #5325 NoBreakCommentFixer - better throw handling (SpacePossum)
* bug #5327 StaticLambdaFixer - fix for arrow function used in class with $this (kubawerlos, SpacePossum)
* bug #5332 Fix file missing for php8 (jderusse)
* bug #5333 Fix file missing for php8 (jderusse)
* minor #5328 Fixed deprecation message version (GrahamCampbell)
* minor #5330 DX: cleanup Github Actions configs (kubawerlos)

Changelog for v2.17.0
---------------------

Expand Down Expand Up @@ -72,6 +82,15 @@ Changelog for v2.17.0
Changelog for v2.16.8
---------------------

* bug #5325 NoBreakCommentFixer - better throw handling (SpacePossum)
* bug #5327 StaticLambdaFixer - fix for arrow function used in class with $this (kubawerlos, SpacePossum)
* bug #5333 Fix file missing for php8 (jderusse)
* minor #5328 Fixed deprecation message version (GrahamCampbell)
* minor #5330 DX: cleanup Github Actions configs (kubawerlos)

Changelog for v2.16.9
---------------------

* bug #5095 Annotation - fix for Windows line endings (SpacePossum)
* bug #5221 NoSuperfluousPhpdocTagsFixer - fix for single line PHPDoc (kubawerlos)
* bug #5225 TernaryOperatorSpacesFixer - fix for alternative control structures (kubawerlos)
Expand Down
3 changes: 2 additions & 1 deletion box.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"finder": [
{
"name": [
"*.php"
"*.php",
"*.php8"
],
"exclude": [
"Test",
Expand Down
2 changes: 1 addition & 1 deletion src/Console/ConfigurationResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ private function validateRules(array $rules)
if (isset($rules[$fixerName]) && $fixer instanceof DeprecatedFixerInterface) {
$successors = $fixer->getSuccessorsNames();
$messageEnd = [] === $successors
? sprintf(' and will be removed in version %d.0.', Application::getMajorVersion())
? sprintf(' and will be removed in version %d.0.', Application::getMajorVersion() + 1)
: sprintf('. Use %s instead.', str_replace('`', '"', Utils::naturalLanguageJoinWithBackticks($successors)));

$message = "Rule \"{$fixerName}\" is deprecated{$messageEnd}";
Expand Down
47 changes: 40 additions & 7 deletions src/Fixer/FunctionNotation/StaticLambdaFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public function isRisky()
protected function applyFix(\SplFileInfo $file, Tokens $tokens)
{
$analyzer = new TokensAnalyzer($tokens);

$expectedFunctionKinds = [T_FUNCTION];

if (\PHP_VERSION_ID >= 70400) {
$expectedFunctionKinds[] = T_FN;
}
Expand All @@ -76,21 +76,22 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
}

$prev = $tokens->getPrevMeaningfulToken($index);

if ($tokens[$prev]->isGivenKind(T_STATIC)) {
continue; // lambda is already 'static'
}

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

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

// ... and where it ends
if ($tokens[$lambdaOpenIndex]->isGivenKind(T_DOUBLE_ARROW)) {
$lambdaEndIndex = $tokens->getNextTokenOfKind($lambdaOpenIndex, [';']);
} else {
if ($tokens[$index]->isGivenKind(T_FUNCTION)) {
$lambdaOpenIndex = $tokens->getNextTokenOfKind($argumentsEndIndex, ['{']);
$lambdaEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $lambdaOpenIndex);
} else { // T_FN
$lambdaOpenIndex = $tokens->getNextTokenOfKind($argumentsEndIndex, [[T_DOUBLE_ARROW]]);
$lambdaEndIndex = $this->findExpressionEnd($tokens, $lambdaOpenIndex);
}

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

/**
* @param int $index
*
* @return int
*/
private function findExpressionEnd(Tokens $tokens, $index)
{
$nextIndex = $tokens->getNextMeaningfulToken($index);

while (null !== $nextIndex) {
/** @var Token $nextToken */
$nextToken = $tokens[$nextIndex];

if ($nextToken->equalsAny([',', ';', [T_CLOSE_TAG]])) {
break;
}

/** @var null|array{isStart: bool, type: int} $blockType */
$blockType = Tokens::detectBlockType($nextToken);

if (null !== $blockType && $blockType['isStart']) {
$nextIndex = $tokens->findBlockEnd($blockType['type'], $nextIndex);
}

$index = $nextIndex;
$nextIndex = $tokens->getNextMeaningfulToken($index);
}

return $index;
}

/**
* Returns 'true' if there is a possible reference to '$this' within the given tokens index range.
*
Expand Down Expand Up @@ -138,6 +170,7 @@ private function hasPossibleReferenceToThis(Tokens $tokens, $startIndex, $endInd

if ($tokens[$i]->equals('$')) {
$nextIndex = $tokens->getNextMeaningfulToken($i);

if ($tokens[$nextIndex]->isGivenKind(T_VARIABLE)) {
return true; // "$$a" case
}
Expand Down
39 changes: 37 additions & 2 deletions tests/Fixer/FunctionNotation/StaticLambdaFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,12 @@ public function provideFixPhp74Cases()
'<?php $a /**/ = /**/ fn() => null;',
],
[
'<?php $a /**/ = /**/static fn() => null;',
'<?php $a /**/ = /**/fn() => null;',
'<?php $a /**/ = /**/static fn() => null; echo $this->foo();',
'<?php $a /**/ = /**/fn() => null; echo $this->foo();',
],
[
'<?php $a /**/ = /**/ static fn() => null ?> <?php echo $this->foo();',
'<?php $a /**/ = /**/ fn() => null ?> <?php echo $this->foo();',
],
[
'<?php
Expand All @@ -277,6 +281,37 @@ public function C()
'<?php static fn($a = ["foo" => "bar"]) => [];',
'<?php fn($a = ["foo" => "bar"]) => [];',
],
[
'<?php class Foo {
public function getNames()
{
return \array_map(
static fn ($item) => $item->getName(),
$this->getItems()
);
}
}',
'<?php class Foo {
public function getNames()
{
return \array_map(
fn ($item) => $item->getName(),
$this->getItems()
);
}
}',
],
[
'<?php class Foo {
public function getNames()
{
return \array_map(
fn ($item) => $item->getName(1, $this->foo()),
$this->getItems()
);
}
}',
],
];
}
}

0 comments on commit b9f8f8e

Please sign in to comment.