Browse Source

Merge branch 'master' into 3.0

# Conflicts:
#	composer.json
#	src/Console/Application.php
Dariusz Ruminski 4 years ago
parent
commit
27f5162115

+ 0 - 2
.github/workflows/ci.yml

@@ -53,7 +53,6 @@ jobs:
           - operating-system: 'ubuntu-20.04'
             php-version: '8.0'
             composer-flags: '--ignore-platform-req=php' # as this is a version not yet officially supported by PHP CS Fixer
-            PHP_CS_FIXER_IGNORE_ENV: 1
 
           - operating-system: 'windows-latest'
             php-version: '7.4'
@@ -127,7 +126,6 @@ jobs:
         run: sed 's/enforceTimeLimit="true"/enforceTimeLimit="false"/g' phpunit.xml.dist > phpunit.xml
 
       - name: Run tests
-        continue-on-error: ${{ matrix.php-version == '8.0' }}
         env:
           PHP_CS_FIXER_IGNORE_ENV: ${{ matrix.PHP_CS_FIXER_IGNORE_ENV }}
           FAST_LINT_TEST_CASES: ${{ matrix.FAST_LINT_TEST_CASES }}

+ 38 - 0
CHANGELOG.md

@@ -3,6 +3,44 @@ CHANGELOG for PHP CS Fixer
 
 This file contains changelogs for stable releases only.
 
+Changelog for v2.18.0
+---------------------
+
+* feature #4943 Add PSR12 ruleset (julienfalque, keradus)
+* feature #5426 Update Symfony ruleset (keradus)
+* feature #5428 Add/Change PHP.MigrationSet to update array/list syntax to short one (keradus)
+* minor #5441 Allow execution under PHP 8 (keradus)
+
+Changelog for v2.17.4
+---------------------
+
+* bug #5379 PhpUnitMethodCasingFixer - Do not modify class name (localheinz)
+* bug #5404 NullableTypeTransformer - constructor property promotion support (Wirone)
+* bug #5433 PhpUnitTestCaseStaticMethodCallsFixer - fix for abstract static method (kubawerlos)
+* minor #5234 DX: Add Docker dev setup (julienfalque, keradus)
+* minor #5391 PhpdocOrderByValueFixer - Add additional annotations to sort (localheinz)
+* minor #5392 PhpdocScalarFixer - Fix description (localheinz)
+* minor #5397 NoExtraBlankLinesFixer - PHP8 throw support (SpacePossum)
+* minor #5399 Add PHP8 integration test (keradus)
+* minor #5405 TypeAlternationTransformer - add support for PHP8 (SpacePossum)
+* minor #5406 SingleSpaceAfterConstructFixer - Attributes, comments and PHPDoc support (SpacePossum)
+* minor #5407 TokensAnalyzer::getClassyElements - return trait imports (SpacePossum)
+* minor #5410 minors (SpacePossum)
+* minor #5411 bump year in LICENSE file (SpacePossum)
+* minor #5414 TypeAlternationTransformer - T_FN support (SpacePossum)
+* minor #5415 Forbid execution under PHP 8.0.0 (keradus)
+* minor #5416 Drop Travis CI (keradus)
+* minor #5419 CI: separate SCA checks to dedicated jobs (keradus)
+* minor #5420 DX: unblock PHPUnit 9.5 (keradus)
+* minor #5423 DX: PHPUnit - disable verbose by default (keradus)
+* minor #5425 Cleanup 3.0 todos (keradus)
+* minor #5427 Plan changing defaults for array_syntax and list_syntax in 3.0 release (keradus)
+* minor #5429 DX: Drop speedtrap PHPUnit listener (keradus)
+* minor #5432 Don't allow unserializing classes with a destructor (jderusse)
+* minor #5435 DX: PHPUnit - groom configuration of time limits (keradus)
+* minor #5439 VisibilityRequiredFixer - support type alternation for properties (keradus)
+* minor #5442 DX: FunctionsAnalyzerTest - add missing 7.0 requirement (keradus)
+
 Changelog for v2.17.3
 ---------------------
 

+ 1 - 1
doc/ruleSets/PHP54Migration.rst

@@ -2,7 +2,7 @@
 Rule set ``@PHP54Migration``
 ============================
 
-Rules to improve code for PHP 5.6 compatibility.
+Rules to improve code for PHP 5.4 compatibility.
 
 Rules
 -----

+ 2 - 2
php-cs-fixer

@@ -21,8 +21,8 @@ if (defined('HHVM_VERSION_ID')) {
     } else {
         exit(1);
     }
-} elseif (!defined('PHP_VERSION_ID') || \PHP_VERSION_ID < 50600 || \PHP_VERSION_ID >= 70500) {
-    fwrite(STDERR, "PHP needs to be a minimum version of PHP 5.6.0 and maximum version of PHP 7.4.*.\n");
+} elseif (!defined('PHP_VERSION_ID') || \PHP_VERSION_ID < 50600 || \PHP_VERSION_ID >= 80100) {
+    fwrite(STDERR, "PHP needs to be a minimum version of PHP 5.6.0 and maximum version of PHP 8.0.*.\n");
     fwrite(STDERR, 'Current PHP version: '.PHP_VERSION.".\n");
 
     if (defined('PHP_VERSION_ID') && \PHP_VERSION_ID === 80000) {

+ 0 - 1
phpstan.neon

@@ -13,7 +13,6 @@ parameters:
     ignoreErrors:
         - '/^Class (Symfony\\Contracts\\EventDispatcher\\Event|Symfony\\Component\\EventDispatcher\\Event) not found.$/'
         - '/^Constant T_NAME_(RELATIVE|FULLY_QUALIFIED|QUALIFIED) not found\.$/'
-        - '/Instantiated class .*TraversableContains is abstract/'
         - '/assertInstanceOf\(\) expects class-string.*, string given/'
         -
             message: '/^Else branch is unreachable because previous condition is always true\.$/'

+ 20 - 1
src/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixer.php

@@ -71,9 +71,12 @@ final class SwitchCaseSemicolonToColonFixer extends AbstractFixer
     protected function applyFix(\SplFileInfo $file, Tokens $tokens)
     {
         foreach ($tokens as $index => $token) {
-            if ($token->isGivenKind([T_CASE, T_DEFAULT])) {
+            if ($token->isGivenKind(T_CASE)) {
                 $this->fixSwitchCase($tokens, $index);
             }
+            if ($token->isGivenKind(T_DEFAULT)) {
+                $this->fixSwitchDefault($tokens, $index);
+            }
         }
     }
 
@@ -110,4 +113,20 @@ final class SwitchCaseSemicolonToColonFixer extends AbstractFixer
             $tokens[$index] = new Token(':');
         }
     }
+
+    /**
+     * @param int $index
+     */
+    protected function fixSwitchDefault(Tokens $tokens, $index)
+    {
+        do {
+            if ($tokens[$index]->equalsAny([':', ';', [T_DOUBLE_ARROW]])) {
+                break;
+            }
+        } while (++$index);
+
+        if ($tokens[$index]->equals(';')) {
+            $tokens[$index] = new Token(':');
+        }
+    }
 }

+ 1 - 1
src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php

@@ -197,7 +197,7 @@ yield  from  baz();
 
             $whitespaceTokenIndex = $index + 1;
 
-            if (';' === $tokens[$whitespaceTokenIndex]->getContent()) {
+            if ($tokens[$whitespaceTokenIndex]->equalsAny([';', ')', [CT::T_ARRAY_SQUARE_BRACE_CLOSE]])) {
                 continue;
             }
 

+ 1 - 1
src/RuleSet/Sets/PHP54MigrationSet.php

@@ -28,6 +28,6 @@ final class PHP54MigrationSet extends AbstractRuleSetDescription
 
     public function getDescription()
     {
-        return 'Rules to improve code for PHP 5.6 compatibility.';
+        return 'Rules to improve code for PHP 5.4 compatibility.';
     }
 }

+ 7 - 1
src/Tokenizer/Analyzer/ArgumentsAnalyzer.php

@@ -14,6 +14,7 @@ namespace PhpCsFixer\Tokenizer\Analyzer;
 
 use PhpCsFixer\Tokenizer\Analyzer\Analysis\ArgumentAnalysis;
 use PhpCsFixer\Tokenizer\Analyzer\Analysis\TypeAnalysis;
+use PhpCsFixer\Tokenizer\CT;
 use PhpCsFixer\Tokenizer\Tokens;
 
 /**
@@ -112,7 +113,12 @@ final class ArgumentsAnalyzer
         for ($index = $argumentStart; $index <= $argumentEnd; ++$index) {
             $token = $tokens[$index];
 
-            if ($token->isComment() || $token->isWhitespace() || $token->isGivenKind(T_ELLIPSIS) || $token->equals('&')) {
+            if (
+                $token->isComment()
+                || $token->isWhitespace()
+                || $token->isGivenKind([T_ELLIPSIS, CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC, CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED, CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE])
+                || $token->equals('&')
+            ) {
                 continue;
             }
 

+ 38 - 23
tests/AutoReview/CiConfigurationTest.php

@@ -15,7 +15,7 @@ namespace PhpCsFixer\Tests\AutoReview;
 use PhpCsFixer\Preg;
 use PhpCsFixer\Tests\TestCase;
 use PhpCsFixer\Tokenizer\Tokens;
-use PHPUnit\Framework\Constraint\TraversableContains;
+use PHPUnit\Framework\Constraint\TraversableContainsIdentical;
 use Symfony\Component\Yaml\Yaml;
 
 /**
@@ -40,10 +40,20 @@ final class CiConfigurationTest extends TestCase
             $supportedVersions[] = '5.6';
         }
 
-        for ($version = $supportedMinPhp; $version <= $supportedMaxPhp; $version += 0.1) {
-            $supportedVersions[] = sprintf('%.1f', $version);
+        if ($supportedMaxPhp >= 8) {
+            $supportedVersions = array_merge(
+                $supportedVersions,
+                self::generateMinorVersionsRange($supportedMinPhp, 7.4)
+            );
+
+            $supportedMinPhp = 8;
         }
 
+        $supportedVersions = array_merge(
+            $supportedVersions,
+            self::generateMinorVersionsRange($supportedMinPhp, $supportedMaxPhp)
+        );
+
         $ciVersions = $this->getAllPhpVersionsUsedByCiForTests();
 
         static::assertGreaterThanOrEqual(1, \count($ciVersions));
@@ -56,7 +66,7 @@ final class CiConfigurationTest extends TestCase
     {
         $ciVersionsForDeployments = $this->getAllPhpVersionsUsedByCiForDeployments();
         $ciVersions = $this->getAllPhpVersionsUsedByCiForTests();
-        $expectedPhp = $this->getMaxPhpVersionFromEntryFile();
+        $expectedPhp = '7.4'; // can't run dev-tools on 8.0 yet; $this->getMaxPhpVersionFromEntryFile();
 
         if (\in_array($expectedPhp.'snapshot', $ciVersions, true)) {
             // last version of used PHP is snapshot. we should test against previous one, that is stable
@@ -74,36 +84,41 @@ final class CiConfigurationTest extends TestCase
         }
     }
 
-    private static function ensureTraversableContainsIsAvailable()
+    private static function generateMinorVersionsRange($from, $to)
     {
-        if (!class_exists(TraversableContains::class)) {
-            static::markTestSkipped('TraversableContains not available.');
+        $range = [];
+
+        for ($version = $from; $version <= $to; $version += 0.1) {
+            $range[] = sprintf('%.1f', $version);
         }
 
-        try {
-            new TraversableContains('');
-        } catch (\Error $e) {
-            if (false === strpos($e->getMessage(), 'Cannot instantiate abstract class')) {
-                throw $e;
-            }
+        return $range;
+    }
 
-            static::markTestSkipped('TraversableContains not available.');
+    private static function ensureTraversableContainsIdenticalIsAvailable()
+    {
+        if (!class_exists(TraversableContainsIdentical::class)) {
+            static::markTestSkipped('TraversableContainsIdentical not available.');
         }
     }
 
     private static function assertUpcomingPhpVersionIsCoveredByCiJob($lastSupportedVersion, array $ciVersions)
     {
-        self::ensureTraversableContainsIsAvailable();
+        if ('8.0' === $lastSupportedVersion) {
+            return; // no further releases available yet
+        }
+
+        self::ensureTraversableContainsIdenticalIsAvailable();
 
         static::assertThat($ciVersions, static::logicalOr(
             // if `$lastsupportedVersion` is already a snapshot version
-            new TraversableContains(sprintf('%.1fsnapshot', $lastSupportedVersion)),
+            new TraversableContainsIdentical(sprintf('%.1fsnapshot', $lastSupportedVersion)),
             // if `$lastsupportedVersion` is not snapshot version, expect CI to run snapshot of next PHP version
-            new TraversableContains('nightly'),
-            new TraversableContains(sprintf('%.1fsnapshot', $lastSupportedVersion + 0.1)),
+            new TraversableContainsIdentical('nightly'),
+            new TraversableContainsIdentical(sprintf('%.1fsnapshot', $lastSupportedVersion + 0.1)),
             // GitHub CI uses just versions, without suffix, e.g. 8.1 for 8.1snapshot as of writing
-            new TraversableContains(sprintf('%.1f', $lastSupportedVersion + 0.1)),
-            new TraversableContains(sprintf('%.1f', round($lastSupportedVersion + 1)))
+            new TraversableContainsIdentical(sprintf('%.1f', $lastSupportedVersion + 0.1)),
+            new TraversableContainsIdentical(sprintf('%.1f', round($lastSupportedVersion + 1)))
         ));
     }
 
@@ -115,11 +130,11 @@ final class CiConfigurationTest extends TestCase
             static::assertContains($expectedVersion, $ciVersions);
         }
 
-        self::ensureTraversableContainsIsAvailable();
+        self::ensureTraversableContainsIdenticalIsAvailable();
 
         static::assertThat($ciVersions, static::logicalOr(
-            new TraversableContains($lastSupportedVersion),
-            new TraversableContains(sprintf('%.1fsnapshot', $lastSupportedVersion))
+            new TraversableContainsIdentical($lastSupportedVersion),
+            new TraversableContainsIdentical(sprintf('%.1fsnapshot', $lastSupportedVersion))
         ));
     }
 

Some files were not shown because too many files changed in this diff