Browse Source

Merge branch '2.16'

* 2.16:
  SwitchAnalyzer - fix for semicolon after case/default
  PHP8 support
  Do not update Composer twice
  Improve InstallViaComposerTest
  Update PhpUnitTestCaseStaticMethodCallsFixer
  PHP8 - mixed type support
  IO - fix cache info message
  NoBreakCommentFixer - fix throw detect
SpacePossum 4 years ago
parent
commit
953c05151e

+ 7 - 5
.composer-require-checker.json

@@ -1,8 +1,5 @@
 {
     "symbol-whitelist" : [
-        "Symfony\\Contracts\\EventDispatcher\\Event",
-        "Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface",
-        "Symfony\\Component\\EventDispatcher\\Event",
         "PhpCsFixer\\PhpunitConstraintIsIdenticalString\\Constraint\\IsIdenticalString",
         "PhpCsFixer\\Tests\\Test\\Constraint\\SameStringsConstraint",
         "PhpCsFixer\\Tests\\Test\\IsIdenticalConstraint",
@@ -15,13 +12,18 @@
         "PHPUnitGoodPractices\\Traits\\ProphecyOverMockObjectTrait",
         "PHPUnitGoodPractices\\Traits\\ProphesizeOnlyInterfaceTrait",
         "Prophecy\\Argument",
+        "Symfony\\Component\\EventDispatcher\\Event",
+        "Symfony\\Contracts\\EventDispatcher\\Event",
+        "Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface",
 
         "null", "true", "false",
         "static", "self", "parent",
         "array", "string", "int", "float", "bool", "iterable", "callable", "void",
-        "T_COALESCE_EQUAL", "T_FN",
-        "T_NAME_QUALIFIED",
+        "T_COALESCE_EQUAL",
+        "T_FN",
+        "T_MATCH",
         "T_NAME_FULLY_QUALIFIED",
+        "T_NAME_QUALIFIED",
         "T_NAME_RELATIVE"
     ],
     "php-core-extensions" : [

+ 1 - 0
.gitattributes

@@ -1,6 +1,7 @@
 # @TODO 3.0 replace following `tests/... export-ignore` with single `tests/ export-ignore`
 /tests/**/*Test.php export-ignore
 /tests/AbstractDoctrineAnnotationFixerTestCase.php export-ignore
+/tests/Console/TestToolInfo.php export-ignore
 /tests/Differ/AbstractDifferTestCase.php export-ignore
 /tests/Fixtures/ export-ignore
 /tests/Linter/AbstractLinterTestCase.php export-ignore

+ 0 - 6
.travis.yml

@@ -20,9 +20,6 @@ before_install:
     # turn off XDebug
     - phpenv config-rm xdebug.ini || return 0
 
-    # Composer v2
-    - composer self-update --2
-
 jobs:
     include:
         -
@@ -115,9 +112,6 @@ jobs:
                 # turn off XDebug
                 - phpenv config-rm xdebug.ini || return 0
 
-                # Composer v2
-                - composer self-update --2
-
                 # Require PHPUnit 8
                 - composer require --dev --no-update phpunit/phpunit:^8
 

+ 13 - 0
doc/rules/alias/random_api_migration.rst

@@ -58,6 +58,19 @@ With configuration: ``['replacements' => ['getrandmax' => 'mt_getrandmax']]``.
     $a = rand($b, $c);
     $a = srand();
 
+Example #3
+~~~~~~~~~~
+
+With configuration: ``['replacements' => ['rand' => 'random_int']]``.
+
+.. code-block:: diff
+
+   --- Original
+   +++ New
+   @@ -1 +1 @@
+   -<?php $a = rand($b, $c);
+   +<?php $a = random_int($b, $c);
+
 Rule sets
 ---------
 

+ 8 - 4
src/Console/ConfigurationResolver.php

@@ -193,9 +193,13 @@ final class ConfigurationResolver
     public function getCacheManager()
     {
         if (null === $this->cacheManager) {
-            if ($this->getUsingCache() && ($this->toolInfo->isInstalledAsPhar() || $this->toolInfo->isInstalledByComposer())) {
+            $cacheFile = $this->getCacheFile();
+
+            if (null === $cacheFile) {
+                $this->cacheManager = new NullCacheManager();
+            } else {
                 $this->cacheManager = new FileCacheManager(
-                    new FileHandler($this->getCacheFile()),
+                    new FileHandler($cacheFile),
                     new Signature(
                         PHP_VERSION,
                         $this->toolInfo->getVersion(),
@@ -206,8 +210,6 @@ final class ConfigurationResolver
                     $this->isDryRun(),
                     $this->getDirectory()
                 );
-            } else {
-                $this->cacheManager = new NullCacheManager();
             }
         }
 
@@ -525,6 +527,8 @@ final class ConfigurationResolver
             }
         }
 
+        $this->usingCache = $this->usingCache && ($this->toolInfo->isInstalledAsPhar() || $this->toolInfo->isInstalledByComposer());
+
         return $this->usingCache;
     }
 

+ 4 - 0
src/Fixer/Alias/RandomApiMigrationFixer.php

@@ -66,6 +66,10 @@ final class RandomApiMigrationFixer extends AbstractFunctionReferenceFixer imple
                     "<?php\n\$a = getrandmax();\n\$a = rand(\$b, \$c);\n\$a = srand();\n",
                     ['replacements' => ['getrandmax' => 'mt_getrandmax']]
                 ),
+                new CodeSample(
+                    "<?php \$a = rand(\$b, \$c);\n",
+                    ['replacements' => ['rand' => 'random_int']]
+                ),
             ],
             null,
             'Risky when the configured functions are overridden.'

+ 13 - 11
src/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixer.php

@@ -30,17 +30,18 @@ final class NativeFunctionTypeDeclarationCasingFixer extends AbstractFixer
     /**
      * https://secure.php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration.
      *
-     * self     PHP 5.0.0
-     * array    PHP 5.1.0
-     * callable PHP 5.4.0
-     * bool     PHP 7.0.0
-     * float    PHP 7.0.0
-     * int      PHP 7.0.0
-     * string   PHP 7.0.0
-     * iterable PHP 7.1.0
-     * void     PHP 7.1.0
-     * object   PHP 7.2.0
-     * static   PHP 8.0.0 (return type only)
+     * self     PHP 5.0
+     * array    PHP 5.1
+     * callable PHP 5.4
+     * bool     PHP 7.0
+     * float    PHP 7.0
+     * int      PHP 7.0
+     * string   PHP 7.0
+     * iterable PHP 7.1
+     * void     PHP 7.1
+     * object   PHP 7.2
+     * static   PHP 8.0 (return type only)
+     * mixed    PHP 8.0
      *
      * @var array<string, true>
      */
@@ -89,6 +90,7 @@ final class NativeFunctionTypeDeclarationCasingFixer extends AbstractFixer
 
         if (\PHP_VERSION_ID >= 80000) {
             $this->hints = array_merge($this->hints, ['static' => true]);
+            $this->hints = array_merge($this->hints, ['mixed' => true]);
         }
 
         $this->functionsAnalyzer = new FunctionsAnalyzer();

+ 3 - 2
src/Fixer/ControlStructure/NoBreakCommentFixer.php

@@ -131,8 +131,9 @@ switch ($foo) {
         $empty = true;
         $fallThrough = true;
         $commentPosition = null;
+        $caseColonIndex = $tokens->getNextTokenOfKind($casePosition, [':', ';']);
 
-        for ($i = $tokens->getNextTokenOfKind($casePosition, [':', ';']) + 1, $max = \count($tokens); $i < $max; ++$i) {
+        for ($i = $caseColonIndex + 1, $max = \count($tokens); $i < $max; ++$i) {
             if ($tokens[$i]->isGivenKind([T_SWITCH, T_IF, T_ELSE, T_ELSEIF, T_FOR, T_FOREACH, T_WHILE, T_DO, T_FUNCTION, T_CLASS])) {
                 $empty = false;
                 $i = $this->getStructureEnd($tokens, $i);
@@ -149,7 +150,7 @@ switch ($foo) {
             if ($tokens[$i]->isGivenKind([T_THROW])) {
                 $previousIndex = $tokens->getPrevMeaningfulToken($i);
 
-                if ($previousIndex === $casePosition || $tokens[$previousIndex]->equalsAny(['{', ';', [T_OPEN_TAG]])) {
+                if ($previousIndex === $caseColonIndex || $tokens[$previousIndex]->equalsAny(['{', ';', [T_OPEN_TAG]])) {
                     $fallThrough = false;
                 }
 

+ 4 - 0
src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php

@@ -188,6 +188,10 @@ final class Foo {
      */
     protected function applyFix(\SplFileInfo $file, Tokens $tokens)
     {
+        if (\PHP_VERSION_ID >= 80000) {
+            unset($this->skippedTypes['mixed']);
+        }
+
         for ($index = $tokens->count() - 1; 0 < $index; --$index) {
             if (
                 !$tokens[$index]->isGivenKind(T_FUNCTION)

+ 18 - 1
src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php

@@ -86,23 +86,30 @@ final class PhpUnitTestCaseStaticMethodCallsFixer extends AbstractPhpUnitFixer i
         'assertContainsOnly' => true,
         'assertContainsOnlyInstancesOf' => true,
         'assertCount' => true,
+        'assertDirectoryDoesNotExist' => true,
         'assertDirectoryExists' => true,
+        'assertDirectoryIsNotReadable' => true,
+        'assertDirectoryIsNotWritable' => true,
         'assertDirectoryIsReadable' => true,
         'assertDirectoryIsWritable' => true,
         'assertDirectoryNotExists' => true,
         'assertDirectoryNotIsReadable' => true,
         'assertDirectoryNotIsWritable' => true,
+        'assertDoesNotMatchRegularExpression' => true,
         'assertEmpty' => true,
+        'assertEqualXMLStructure' => true,
         'assertEquals' => true,
         'assertEqualsCanonicalizing' => true,
         'assertEqualsIgnoringCase' => true,
         'assertEqualsWithDelta' => true,
-        'assertEqualXMLStructure' => true,
         'assertFalse' => true,
+        'assertFileDoesNotExist' => true,
         'assertFileEquals' => true,
         'assertFileEqualsCanonicalizing' => true,
         'assertFileEqualsIgnoringCase' => true,
         'assertFileExists' => true,
+        'assertFileIsNotReadable' => true,
+        'assertFileIsNotWritable' => true,
         'assertFileIsReadable' => true,
         'assertFileIsWritable' => true,
         'assertFileNotEquals' => true,
@@ -120,20 +127,24 @@ final class PhpUnitTestCaseStaticMethodCallsFixer extends AbstractPhpUnitFixer i
         'assertIsArray' => true,
         'assertIsBool' => true,
         'assertIsCallable' => true,
+        'assertIsClosedResource' => true,
         'assertIsFloat' => true,
         'assertIsInt' => true,
         'assertIsIterable' => true,
         'assertIsNotArray' => true,
         'assertIsNotBool' => true,
         'assertIsNotCallable' => true,
+        'assertIsNotClosedResource' => true,
         'assertIsNotFloat' => true,
         'assertIsNotInt' => true,
         'assertIsNotIterable' => true,
         'assertIsNotNumeric' => true,
         'assertIsNotObject' => true,
+        'assertIsNotReadable' => true,
         'assertIsNotResource' => true,
         'assertIsNotScalar' => true,
         'assertIsNotString' => true,
+        'assertIsNotWritable' => true,
         'assertIsNumeric' => true,
         'assertIsObject' => true,
         'assertIsReadable' => true,
@@ -150,6 +161,7 @@ final class PhpUnitTestCaseStaticMethodCallsFixer extends AbstractPhpUnitFixer i
         'assertJsonStringNotEqualsJsonString' => true,
         'assertLessThan' => true,
         'assertLessThanOrEqual' => true,
+        'assertMatchesRegularExpression' => true,
         'assertNan' => true,
         'assertNotContains' => true,
         'assertNotContainsEquals' => true,
@@ -171,6 +183,7 @@ final class PhpUnitTestCaseStaticMethodCallsFixer extends AbstractPhpUnitFixer i
         'assertNotSameSize' => true,
         'assertNotTrue' => true,
         'assertNull' => true,
+        'assertObjectEquals' => true,
         'assertObjectHasAttribute' => true,
         'assertObjectNotHasAttribute' => true,
         'assertRegExp' => true,
@@ -215,6 +228,9 @@ final class PhpUnitTestCaseStaticMethodCallsFixer extends AbstractPhpUnitFixer i
         'countOf' => true,
         'directoryExists' => true,
         'equalTo' => true,
+        'equalToCanonicalizing' => true,
+        'equalToIgnoringCase' => true,
+        'equalToWithDelta' => true,
         'fail' => true,
         'fileExists' => true,
         'getCount' => true,
@@ -245,6 +261,7 @@ final class PhpUnitTestCaseStaticMethodCallsFixer extends AbstractPhpUnitFixer i
         'markTestSkipped' => true,
         'matches' => true,
         'matchesRegularExpression' => true,
+        'objectEquals' => true,
         'objectHasAttribute' => true,
         'readAttribute' => true,
         'resetCount' => true,

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