Browse Source

Merge branch '2.2'

# Conflicts:
#	.travis.yml
#	tests/ConfigurationException/InvalidConfigurationExceptionTest.php
#	tests/Fixer/LanguageConstruct/FunctionToConstantFixerTest.php
Dariusz Ruminski 7 years ago
parent
commit
9495672d9e

+ 2 - 0
.travis.yml

@@ -117,3 +117,5 @@ jobs:
                 on:
                 on:
                     repo: FriendsOfPHP/PHP-CS-Fixer
                     repo: FriendsOfPHP/PHP-CS-Fixer
                     tags: true
                     tags: true
+            after_deploy:
+                - ./dev-tools/trigger-website.sh ${TRAVIS_TOKEN} ${TRAVIS_TAG}

+ 28 - 0
dev-tools/trigger-website.sh

@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+set -e
+
+TOKEN=$1
+MSG_SUFFIX=$2
+
+if [ ! -z $MSG_SUFFIX ]
+then
+    MSG_SUFFIX=" for ${MSG_SUFFIX}"
+fi
+
+REPO=$(sed "s@/@%2F@g" <<< "PHP-CS-Fixer/PHP-CS-Fixer.github.io")
+
+body="{
+    \"request\": {
+        \"branch\": \"generate\",
+        \"message\": \"Build triggered automatically${MSG_SUFFIX}\"
+    }
+}"
+
+curl -s -X POST \
+    -H "Content-Type: application/json" \
+    -H "Accept: application/json" \
+    -H "Travis-API-Version: 3" \
+    -H "User-Agent: API Explorer" \
+    -H "Authorization: token ${TOKEN}" \
+    -d "${body}" \
+    https://api.travis-ci.org/repo/${REPO}/requests

+ 14 - 0
src/ConfigurationException/InvalidFixerConfigurationException.php

@@ -23,6 +23,11 @@ use PhpCsFixer\Console\Command\FixCommand;
  */
  */
 class InvalidFixerConfigurationException extends InvalidConfigurationException
 class InvalidFixerConfigurationException extends InvalidConfigurationException
 {
 {
+    /**
+     * @var string
+     */
+    private $fixerName;
+
     /**
     /**
      * @param string          $fixerName
      * @param string          $fixerName
      * @param string          $message
      * @param string          $message
@@ -35,5 +40,14 @@ class InvalidFixerConfigurationException extends InvalidConfigurationException
             FixCommand::EXIT_STATUS_FLAG_HAS_INVALID_FIXER_CONFIG,
             FixCommand::EXIT_STATUS_FLAG_HAS_INVALID_FIXER_CONFIG,
             $previous
             $previous
         );
         );
+        $this->fixerName = $fixerName;
+    }
+
+    /**
+     * @return string
+     */
+    public function getFixerName()
+    {
+        return $this->fixerName;
     }
     }
 }
 }

+ 9 - 3
src/Console/ConfigurationResolver.php

@@ -657,9 +657,15 @@ final class ConfigurationResolver
          *
          *
          * @see RuleSet::resolveSet()
          * @see RuleSet::resolveSet()
          */
          */
-        $ruleSet = RuleSet::create(array_map(function () {
-            return true;
-        }, $rules));
+        $ruleSet = [];
+        foreach ($rules as $key => $value) {
+            if (is_int($key)) {
+                throw new InvalidConfigurationException(sprintf('Missing value for "%s" rule/set.', $value));
+            }
+
+            $ruleSet[$key] = true;
+        }
+        $ruleSet = new RuleSet($ruleSet);
 
 
         /** @var string[] $configuredFixers */
         /** @var string[] $configuredFixers */
         $configuredFixers = array_keys($ruleSet->getRules());
         $configuredFixers = array_keys($ruleSet->getRules());

+ 5 - 0
src/Fixer/Basic/Psr0Fixer.php

@@ -85,6 +85,11 @@ class InvalidName {}
                     return;
                     return;
                 }
                 }
 
 
+                $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
+                if ($prevToken->isGivenKind(T_NEW)) {
+                    return;
+                }
+
                 $classyIndex = $tokens->getNextMeaningfulToken($index);
                 $classyIndex = $tokens->getNextMeaningfulToken($index);
                 $classyName = $tokens[$classyIndex]->getContent();
                 $classyName = $tokens[$classyIndex]->getContent();
             }
             }

+ 5 - 0
src/Fixer/Basic/Psr4Fixer.php

@@ -68,6 +68,11 @@ class InvalidName {}
                     return;
                     return;
                 }
                 }
 
 
+                $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
+                if ($prevToken->isGivenKind(T_NEW)) {
+                    return;
+                }
+
                 $classyIndex = $tokens->getNextMeaningfulToken($index);
                 $classyIndex = $tokens->getNextMeaningfulToken($index);
                 $classyName = $tokens[$classyIndex]->getContent();
                 $classyName = $tokens[$classyIndex]->getContent();
             }
             }

+ 41 - 0
tests/AutoReview/ProjectFixerConfigurationTest.php

@@ -0,0 +1,41 @@
+<?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\Console\ConfigurationResolver;
+use PHPUnit\Framework\TestCase;
+
+/**
+ * @author SpacePossum
+ *
+ * @internal
+ *
+ * @coversNothing
+ * @group auto-review
+ */
+final class ProjectFixerConfigurationTest extends TestCase
+{
+    public function testCreate()
+    {
+        /** @var \PhpCsFixer\Config $config */
+        $config = require __DIR__.'/../../.php_cs.dist';
+
+        $this->assertInstanceOf('PhpCsFixer\Config', $config);
+        $this->assertEmpty($config->getCustomFixers());
+        $this->assertNotEmpty($config->getRules());
+
+        // call so the fixers get configured to reveal issue (like deprecated configuration used etc.)
+        $resolver = new ConfigurationResolver($config, [], __DIR__);
+        $resolver->getFixers();
+    }
+}

+ 13 - 20
tests/ConfigurationException/InvalidConfigurationExceptionTest.php

@@ -12,7 +12,7 @@
 
 
 namespace PhpCsFixer\Tests\ConfigurationException;
 namespace PhpCsFixer\Tests\ConfigurationException;
 
 
-use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
+use PhpCsFixer\ConfigurationException\InvalidConfigurationException;
 use PhpCsFixer\Console\Command\FixCommand;
 use PhpCsFixer\Console\Command\FixCommand;
 use PHPUnit\Framework\TestCase;
 use PHPUnit\Framework\TestCase;
 
 
@@ -21,49 +21,42 @@ use PHPUnit\Framework\TestCase;
  *
  *
  * @internal
  * @internal
  *
  *
- * @covers \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException
+ * @covers \PhpCsFixer\ConfigurationException\InvalidConfigurationException
  */
  */
 final class InvalidConfigurationExceptionTest extends TestCase
 final class InvalidConfigurationExceptionTest extends TestCase
 {
 {
-    public function testIsInvalidConfigurationException()
+    public function testIsInvalidArgumentException()
     {
     {
-        $exception = new InvalidFixerConfigurationException(
-            'hal',
-            'I cannot do that, Dave.'
-        );
+        $exception = new InvalidConfigurationException('I cannot do that, Dave.');
 
 
-        $this->assertInstanceOf(\PhpCsFixer\ConfigurationException\InvalidConfigurationException::class, $exception);
+        $this->assertInstanceOf(\InvalidArgumentException::class, $exception);
     }
     }
 
 
     public function testDefaults()
     public function testDefaults()
     {
     {
-        $fixerName = 'hal';
         $message = 'I cannot do that, Dave.';
         $message = 'I cannot do that, Dave.';
 
 
-        $exception = new InvalidFixerConfigurationException(
-            $fixerName,
-            $message
-        );
+        $exception = new InvalidConfigurationException($message);
 
 
-        $this->assertSame(sprintf('[%s] %s', $fixerName, $message), $exception->getMessage());
-        $this->assertSame(FixCommand::EXIT_STATUS_FLAG_HAS_INVALID_FIXER_CONFIG, $exception->getCode());
+        $this->assertSame($message, $exception->getMessage());
+        $this->assertSame(FixCommand::EXIT_STATUS_FLAG_HAS_INVALID_CONFIG, $exception->getCode());
         $this->assertNull($exception->getPrevious());
         $this->assertNull($exception->getPrevious());
     }
     }
 
 
     public function testConstructorSetsValues()
     public function testConstructorSetsValues()
     {
     {
-        $fixerName = 'hal';
         $message = 'I cannot do that, Dave.';
         $message = 'I cannot do that, Dave.';
+        $code = 9000;
         $previous = new \RuntimeException();
         $previous = new \RuntimeException();
 
 
-        $exception = new InvalidFixerConfigurationException(
-            $fixerName,
+        $exception = new InvalidConfigurationException(
             $message,
             $message,
+            $code,
             $previous
             $previous
         );
         );
 
 
-        $this->assertSame(sprintf('[%s] %s', $fixerName, $message), $exception->getMessage());
-        $this->assertSame(FixCommand::EXIT_STATUS_FLAG_HAS_INVALID_FIXER_CONFIG, $exception->getCode());
+        $this->assertSame($message, $exception->getMessage());
+        $this->assertSame($code, $exception->getCode());
         $this->assertSame($previous, $exception->getPrevious());
         $this->assertSame($previous, $exception->getPrevious());
     }
     }
 }
 }

+ 18 - 12
tests/ConfigurationException/InvalidFixerConfigurationExceptionTest.php

@@ -12,7 +12,7 @@
 
 
 namespace PhpCsFixer\Tests\ConfigurationException;
 namespace PhpCsFixer\Tests\ConfigurationException;
 
 
-use PhpCsFixer\ConfigurationException\InvalidConfigurationException;
+use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
 use PhpCsFixer\Console\Command\FixCommand;
 use PhpCsFixer\Console\Command\FixCommand;
 use PHPUnit\Framework\TestCase;
 use PHPUnit\Framework\TestCase;
 
 
@@ -21,42 +21,48 @@ use PHPUnit\Framework\TestCase;
  *
  *
  * @internal
  * @internal
  *
  *
- * @covers \PhpCsFixer\ConfigurationException\InvalidConfigurationException
+ * @covers \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException
  */
  */
 final class InvalidFixerConfigurationExceptionTest extends TestCase
 final class InvalidFixerConfigurationExceptionTest extends TestCase
 {
 {
     public function testIsInvalidArgumentException()
     public function testIsInvalidArgumentException()
     {
     {
-        $exception = new InvalidConfigurationException('I cannot do that, Dave.');
+        $exception = new InvalidFixerConfigurationException('foo', 'I cannot do that, Dave.');
 
 
-        $this->assertInstanceOf('InvalidArgumentException', $exception);
+        $this->assertInstanceOf(\PhpCsFixer\ConfigurationException\InvalidConfigurationException::class, $exception);
     }
     }
 
 
     public function testDefaults()
     public function testDefaults()
     {
     {
+        $fixerName = 'hal';
         $message = 'I cannot do that, Dave.';
         $message = 'I cannot do that, Dave.';
 
 
-        $exception = new InvalidConfigurationException($message);
+        $exception = new InvalidFixerConfigurationException(
+            $fixerName,
+            $message
+        );
 
 
-        $this->assertSame($message, $exception->getMessage());
-        $this->assertSame(FixCommand::EXIT_STATUS_FLAG_HAS_INVALID_CONFIG, $exception->getCode());
+        $this->assertSame(sprintf('[%s] %s', $fixerName, $message), $exception->getMessage());
+        $this->assertSame(FixCommand::EXIT_STATUS_FLAG_HAS_INVALID_FIXER_CONFIG, $exception->getCode());
+        $this->assertSame($fixerName, $exception->getFixerName());
         $this->assertNull($exception->getPrevious());
         $this->assertNull($exception->getPrevious());
     }
     }
 
 
     public function testConstructorSetsValues()
     public function testConstructorSetsValues()
     {
     {
+        $fixerName = 'hal';
         $message = 'I cannot do that, Dave.';
         $message = 'I cannot do that, Dave.';
-        $code = 9000;
         $previous = new \RuntimeException();
         $previous = new \RuntimeException();
 
 
-        $exception = new InvalidConfigurationException(
+        $exception = new InvalidFixerConfigurationException(
+            $fixerName,
             $message,
             $message,
-            $code,
             $previous
             $previous
         );
         );
 
 
-        $this->assertSame($message, $exception->getMessage());
-        $this->assertSame($code, $exception->getCode());
+        $this->assertSame(sprintf('[%s] %s', $fixerName, $message), $exception->getMessage());
+        $this->assertSame(FixCommand::EXIT_STATUS_FLAG_HAS_INVALID_FIXER_CONFIG, $exception->getCode());
+        $this->assertSame($fixerName, $exception->getFixerName());
         $this->assertSame($previous, $exception->getPrevious());
         $this->assertSame($previous, $exception->getPrevious());
     }
     }
 }
 }

+ 24 - 0
tests/Fixer/Basic/Psr0FixerTest.php

@@ -175,6 +175,30 @@ EOF;
         $this->doTest($expected, null, $file);
         $this->doTest($expected, null, $file);
     }
     }
 
 
+    /**
+     * @requires PHP 7.0
+     */
+    public function testIgnoreAnonymousClass()
+    {
+        $file = $this->getTestFile(__FILE__);
+
+        $expected = <<<'EOF'
+<?php
+namespace PhpCsFixer\Tests\Fixer\Basic;
+new class implements Countable {};
+EOF;
+
+        $this->doTest($expected, null, $file);
+
+        $expected = <<<'EOF'
+<?php
+namespace PhpCsFixer\Tests\Fixer\Basic;
+new class extends stdClass {};
+EOF;
+
+        $this->doTest($expected, null, $file);
+    }
+
     /**
     /**
      * @param string $filename
      * @param string $filename
      *
      *

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