Browse Source

Merge branch '2.15'

# Conflicts:
#	src/Console/Application.php
Dariusz Ruminski 5 years ago
parent
commit
e9fe982be1

+ 1 - 1
.travis.yml

@@ -145,7 +145,7 @@ jobs:
 
         -
             stage: Deployment
-            php: 7.1
+            php: 7.3
             install: ./dev-tools/build.sh
             script:
                 - PHP_CS_FIXER_TEST_ALLOW_SKIPPING_SMOKE_TESTS=0 vendor/bin/phpunit tests/Smoke/

+ 21 - 0
CHANGELOG.md

@@ -3,6 +3,13 @@ CHANGELOG for PHP CS Fixer
 
 This file contains changelogs for stable releases only.
 
+Changelog for v2.15.3
+---------------------
+
+* bug #4533 Revert PHP7.4 - Add "str_split" => "mb_str_split" mapping (keradus)
+* minor #4264 DX: AutoReview - ensure Travis handle all needed PHP versions (keradus)
+* minor #4524 MethodArgumentSpaceFixerTest - make explicit configuration to prevent fail on configuration change (keradus)
+
 Changelog for v2.15.2
 ---------------------
 
@@ -66,6 +73,13 @@ Changelog for v2.15.0
 * minor #4398 New ruleset "@PHP73Migration" (gharlan)
 * minor #4399 Fix 2.15 line (keradus)
 
+Changelog for v2.14.6
+---------------------
+
+* bug #4533 Revert PHP7.4 - Add "str_split" => "mb_str_split" mapping (keradus)
+* minor #4264 DX: AutoReview - ensure Travis handle all needed PHP versions (keradus)
+* minor #4524 MethodArgumentSpaceFixerTest - make explicit configuration to prevent fail on configuration change (keradus)
+
 Changelog for v2.14.5
 ---------------------
 
@@ -317,6 +331,13 @@ Changelog for v2.13.0
 * minor #3873 Add the native_function_invocation fixer in the Symfony:risky ruleset (stof)
 * minor #3979 DX: enable php_unit_method_casing (keradus)
 
+Changelog for v2.12.12
+----------------------
+
+* bug #4533 Revert PHP7.4 - Add "str_split" => "mb_str_split" mapping (keradus)
+* minor #4264 DX: AutoReview - ensure Travis handle all needed PHP versions (keradus)
+* minor #4524 MethodArgumentSpaceFixerTest - make explicit configuration to prevent fail on configuration change (keradus)
+
 Changelog for v2.12.11
 ----------------------
 

+ 2 - 2
README.rst

@@ -46,7 +46,7 @@ or with specified version:
 
 .. code-block:: bash
 
-    $ wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.15.2/php-cs-fixer.phar -O php-cs-fixer
+    $ wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.15.3/php-cs-fixer.phar -O php-cs-fixer
 
 or with curl:
 
@@ -1912,7 +1912,7 @@ Config file
 
 Instead of using command line options to customize the rule, you can save the
 project configuration in a ``.php_cs.dist`` file in the root directory of your project.
-The file must return an instance of `PhpCsFixer\\ConfigInterface <https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v2.15.2/src/ConfigInterface.php>`_
+The file must return an instance of `PhpCsFixer\\ConfigInterface <https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v2.15.3/src/ConfigInterface.php>`_
 which lets you configure the rules, the files and directories that
 need to be analyzed. You may also create ``.php_cs`` file, which is
 the local configuration that will be used instead of the project configuration. It

+ 3 - 2
composer.json

@@ -40,9 +40,10 @@
         "php-cs-fixer/accessible-object": "^1.0",
         "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.1",
         "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.1",
-        "phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1",
+        "phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.1",
         "phpunitgoodpractices/traits": "^1.8",
-        "symfony/phpunit-bridge": "^4.3"
+        "symfony/phpunit-bridge": "^4.3",
+        "symfony/yaml": "^3.0 || ^4.0"
     },
     "suggest": {
         "ext-mbstring": "For handling non-UTF8 characters in cache signature.",

+ 1 - 19
src/Fixer/Alias/MbStrFunctionsFixer.php

@@ -28,7 +28,6 @@ final class MbStrFunctionsFixer extends AbstractFunctionReferenceFixer
      * @var array the list of the string-related function names and their mb_ equivalent
      */
     private static $functionsMap = [
-        'str_split' => ['alternativeName' => 'mb_str_split', 'argumentCount' => [1, 2, 3]],
         'stripos' => ['alternativeName' => 'mb_stripos', 'argumentCount' => [2, 3]],
         'stristr' => ['alternativeName' => 'mb_stristr', 'argumentCount' => [2, 3]],
         'strlen' => ['alternativeName' => 'mb_strlen', 'argumentCount' => [1]],
@@ -43,23 +42,6 @@ final class MbStrFunctionsFixer extends AbstractFunctionReferenceFixer
         'substr_count' => ['alternativeName' => 'mb_substr_count', 'argumentCount' => [2, 3, 4]],
     ];
 
-    /**
-     * @var array<string, array>
-     */
-    private $functions;
-
-    public function __construct()
-    {
-        parent::__construct();
-
-        $this->functions = array_filter(
-            self::$functionsMap,
-            static function (array $mapping) {
-                return \function_exists($mapping['alternativeName']);
-            }
-        );
-    }
-
     /**
      * {@inheritdoc}
      */
@@ -104,7 +86,7 @@ $a = substr_count($a, $b);
     protected function applyFix(\SplFileInfo $file, Tokens $tokens)
     {
         $argumentsAnalyzer = new ArgumentsAnalyzer();
-        foreach ($this->functions as $functionIdentity => $functionReplacement) {
+        foreach (self::$functionsMap as $functionIdentity => $functionReplacement) {
             $currIndex = 0;
             while (null !== $currIndex) {
                 // try getting function reference and translate boundaries for humans

+ 140 - 0
tests/AutoReview/TravisTest.php

@@ -0,0 +1,140 @@
+<?php
+
+/*
+ * This file is part of PHP CS Fixer.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *     Dariusz Rumiński <dariusz.ruminski@gmail.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace PhpCsFixer\Tests\AutoReview;
+
+use PhpCsFixer\Preg;
+use PhpCsFixer\Tests\TestCase;
+use PhpCsFixer\Tokenizer\Tokens;
+use PHPUnit\Framework\Constraint\TraversableContains;
+use Symfony\Component\Yaml\Yaml;
+
+/**
+ * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
+ *
+ * @internal
+ *
+ * @coversNothing
+ * @group auto-review
+ * @group covers-nothing
+ */
+final class TravisTest extends TestCase
+{
+    public function testTestJobsRunOnEachPhp()
+    {
+        $expectedVersions = [];
+        $expectedMinPhp = (float) $this->getMinPhpVersionFromEntryFile();
+        $expectedMaxPhp = (float) $this->getMaxPhpVersionFromEntryFile();
+
+        if ($expectedMinPhp < 7) {
+            $expectedMinPhp = 7;
+            $expectedVersions[] = '5.6';
+        }
+
+        for ($version = $expectedMinPhp; $version <= $expectedMaxPhp; $version += 0.1) {
+            $expectedVersions[] = sprintf('%.1f', $version);
+        }
+
+        $jobs = array_filter($this->getTravisJobs(), function ($job) {
+            return false !== strpos($job['stage'], 'Test');
+        });
+        static::assertGreaterThanOrEqual(1, \count($jobs));
+
+        $versions = array_map(function ($job) {
+            return $job['php'];
+        }, $jobs);
+
+        foreach ($expectedVersions as $expectedVersion) {
+            static::assertContains($expectedVersion, $versions);
+        }
+
+        if (!class_exists(TraversableContains::class)) {
+            static::markTestSkipped('TraversableContains not available.');
+        }
+
+        static::assertThat($versions, static::logicalOr(
+            new TraversableContains('nightly'),
+            new TraversableContains(sprintf('%.1fsnapshot', end($expectedVersions) + 0.1))
+        ));
+    }
+
+    public function testDeploymentJobsRunOnLatestPhp()
+    {
+        $jobs = array_filter($this->getTravisJobs(), function ($job) {
+            return 'Deployment' === $job['stage'];
+        });
+        static::assertGreaterThanOrEqual(1, \count($jobs));
+
+        $expectedPhp = $this->getMaxPhpVersionFromEntryFile();
+
+        foreach ($jobs as $job) {
+            $jobPhp = (string) $job['php'];
+            static::assertTrue(
+                version_compare($expectedPhp, $jobPhp, 'eq'),
+                sprintf('Expects %s to be %s', $jobPhp, $expectedPhp)
+            );
+        }
+    }
+
+    private function convertPhpVerIdToNiceVer($verId)
+    {
+        $matchResult = Preg::match('/^(?<major>\d{1,2})(?<minor>\d{2})(?<patch>\d{2})$/', $verId, $capture);
+        if (1 !== $matchResult) {
+            throw new \LogicException("Can't parse version id.");
+        }
+
+        return sprintf('%d.%d', $capture['major'], $capture['minor']);
+    }
+
+    private function getMaxPhpVersionFromEntryFile()
+    {
+        $tokens = Tokens::fromCode(file_get_contents(__DIR__.'/../../php-cs-fixer'));
+        $sequence = $tokens->findSequence([
+            [T_STRING, 'PHP_VERSION_ID'],
+            [T_IS_GREATER_OR_EQUAL],
+            [T_LNUMBER],
+        ]);
+
+        if (null === $sequence) {
+            throw new \LogicException("Can't find version - perhaps entry file was modified?");
+        }
+
+        $phpVerId = end($sequence)->getContent();
+
+        return $this->convertPhpVerIdToNiceVer((string) ($phpVerId - 100));
+    }
+
+    private function getMinPhpVersionFromEntryFile()
+    {
+        $tokens = Tokens::fromCode(file_get_contents(__DIR__.'/../../php-cs-fixer'));
+        $sequence = $tokens->findSequence([
+            [T_STRING, 'PHP_VERSION_ID'],
+            '<',
+            [T_LNUMBER],
+        ]);
+
+        if (null === $sequence) {
+            throw new \LogicException("Can't find version - perhaps entry file was modified?");
+        }
+
+        $phpVerId = end($sequence)->getContent();
+
+        return $this->convertPhpVerIdToNiceVer($phpVerId);
+    }
+
+    private function getTravisJobs()
+    {
+        $yaml = Yaml::parse(file_get_contents(__DIR__.'/../../.travis.yml'));
+
+        return $yaml['jobs']['include'];
+    }
+}

+ 1 - 14
tests/Fixer/Alias/MbStrFunctionsFixerTest.php

@@ -37,7 +37,7 @@ final class MbStrFunctionsFixerTest extends AbstractFixerTestCase
 
     public function provideFixCases()
     {
-        $cases = [
+        return [
             ['<?php $x = "strlen";'],
             ['<?php $x = Foo::strlen("bar");'],
             ['<?php $x = new strlen("bar");'],
@@ -62,18 +62,5 @@ final class MbStrFunctionsFixerTest extends AbstractFixerTestCase
                 }',
             ],
         ];
-
-        if (\function_exists('mb_str_split')) {
-            $cases[] = [
-                '<?php $a = mb_str_split($a);',
-                '<?php $a = str_split($a);',
-            ];
-        } else {
-            $cases[] = [
-                '<?php $a = str_split($a);',
-            ];
-        }
-
-        return $cases;
     }
 }

+ 28 - 1
tests/Fixer/FunctionNotation/MethodArgumentSpaceFixerTest.php

@@ -333,13 +333,40 @@ EOTXTb
     );
 ",
             ],
-            'with_random_comments' => [
+            'with_random_comments on_multiline:ignore' => [
                 '<?php xyz#
  (#
 ""#
 ,#
 $a#
 );',
+                null,
+                ['on_multiline' => 'ignore'],
+            ],
+            'with_random_comments on_multiline:ensure_single_line' => [
+                '<?php xyz#
+ (#
+""#
+,#
+$a#
+);',
+                null,
+                ['on_multiline' => 'ensure_single_line'],
+            ],
+            'with_random_comments on_multiline:ensure_fully_multiline' => [
+                '<?php xyz#
+ (#
+""#
+,#
+$a#
+ );',
+                '<?php xyz#
+ (#
+""#
+,#
+$a#
+);',
+                ['on_multiline' => 'ensure_fully_multiline'],
             ],
             'keep_multiple_spaces_after_comma_with_newlines' => [
                 "<?php xyz(\$a=10,\n\$b=20);",