Browse Source

Merge branch '1.12'

Conflicts:
	.php_cs
	README.rst
	src/Config/Config.php
	src/Console/Command/FixCommand.php
	src/Finder/DefaultFinder.php
	src/Fixer/Contrib/ShortEchoTagFixer.php
	src/Fixer/Symfony/UnusedUseFixer.php
Dariusz Ruminski 9 years ago
parent
commit
b7ba0a8228

+ 2 - 2
.php_cs.dist

@@ -9,7 +9,7 @@ This source file is subject to the MIT license that is bundled
 with this source code in the file LICENSE.
 EOF;
 
-return Symfony\CS\Config\Config::create()
+return Symfony\CS\Config::create()
     ->setRiskyAllowed(true)
     ->setRules(array(
         '@Symfony' => true,
@@ -22,7 +22,7 @@ return Symfony\CS\Config\Config::create()
         'strict_param' => true,
     ))
     ->finder(
-        Symfony\CS\Finder\DefaultFinder::create()
+        Symfony\CS\Finder::create()
             ->exclude('tests/Fixtures')
             ->in(__DIR__)
     )

+ 6 - 6
README.rst

@@ -744,12 +744,12 @@ The example below will add two fixers to the default list of PSR2 set fixers:
 
     <?php
 
-    $finder = Symfony\CS\Finder\DefaultFinder::create()
+    $finder = Symfony\CS\Finder::create()
         ->exclude('somedir')
         ->in(__DIR__)
     ;
 
-    return Symfony\CS\Config\Config::create()
+    return Symfony\CS\Config::create()
         ->setRules(array(
             '@PSR2' => true,
             'strict_param' => true,
@@ -765,12 +765,12 @@ The following example shows how to use all ``Symfony`` Fixers but the ``short_ta
 
     <?php
 
-    $finder = Symfony\CS\Finder\DefaultFinder::create()
+    $finder = Symfony\CS\Finder::create()
         ->exclude('somedir')
         ->in(__DIR__)
     ;
 
-    return Symfony\CS\Config\Config::create()
+    return Symfony\CS\Config::create()
         ->setRules(array(
             '@Symfony' => true,
             'short_tag' => false,
@@ -796,7 +796,7 @@ Cache can be disabled via ``--using-cache`` option or config file:
 
     <?php
 
-    return Symfony\CS\Config\Config::create()
+    return Symfony\CS\Config::create()
         ->setUsingCache(false)
     ;
 
@@ -806,7 +806,7 @@ Cache file can be specified via ``--cache-file`` option or config file:
 
     <?php
 
-    return Symfony\CS\Config\Config::create()
+    return Symfony\CS\Config::create()
         ->setCacheFile(__DIR__.'/.php_cs.cache')
     ;
 

+ 245 - 0
src/Config.php

@@ -0,0 +1,245 @@
+<?php
+
+/*
+ * This file is part of the PHP CS utility.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Symfony\CS;
+
+use Symfony\CS\Finder\DefaultFinder;
+
+/**
+ * @author Fabien Potencier <fabien@symfony.com>
+ * @author Katsuhiro Ogawa <ko.fivestar@gmail.com>
+ * @author Dariusz Rumiñski <dariusz.ruminski@gmail.com>
+ */
+class Config implements ConfigInterface
+{
+    protected $name;
+    protected $description;
+    protected $finder;
+    protected $fixers = array();
+    protected $dir;
+    protected $customFixers = array();
+    protected $usingCache = true;
+    protected $usingLinter = true;
+    protected $hideProgress = false;
+    protected $cacheFile = '.php_cs.cache';
+    protected $phpExecutable;
+    protected $isRiskyAllowed = false;
+    protected $rules = array('@PSR2' => true);
+
+    public function __construct($name = 'default', $description = 'A default configuration')
+    {
+        $this->name = $name;
+        $this->description = $description;
+        $this->finder = new DefaultFinder();
+    }
+
+    public static function create()
+    {
+        return new static();
+    }
+
+    public function setDir($dir)
+    {
+        $this->dir = $dir;
+
+        return $this;
+    }
+
+    public function setUsingCache($usingCache)
+    {
+        $this->usingCache = $usingCache;
+
+        return $this;
+    }
+
+    public function setUsingLinter($usingLinter)
+    {
+        $this->usingLinter = $usingLinter;
+
+        return $this;
+    }
+
+    public function getDir()
+    {
+        return $this->dir;
+    }
+
+    public function finder(\Traversable $finder)
+    {
+        $this->finder = $finder;
+
+        return $this;
+    }
+
+    public function getFinder()
+    {
+        if ($this->finder instanceof FinderInterface && $this->dir !== null) {
+            $this->finder->setDir($this->dir);
+        }
+
+        return $this->finder;
+    }
+
+    /**
+     * Set fixers.
+     *
+     * @param FixerInterface[] $fixers
+     *
+     * @return $this
+     */
+    public function fixers(array $fixers)
+    {
+        $this->fixers = $fixers;
+
+        return $this;
+    }
+
+    public function getFixers()
+    {
+        return $this->fixers;
+    }
+
+    public function getName()
+    {
+        return $this->name;
+    }
+
+    public function getDescription()
+    {
+        return $this->description;
+    }
+
+    public function getHideProgress()
+    {
+        return $this->hideProgress;
+    }
+
+    public function addCustomFixer(FixerInterface $fixer)
+    {
+        $this->customFixers[] = $fixer;
+
+        return $this;
+    }
+
+    public function addCustomFixers($fixers)
+    {
+        if (false === is_array($fixers) && false === $fixers instanceof \Traversable) {
+            throw new \InvalidArgumentException(sprintf(
+                'Argument must be an array or a Traversable, got "%s".',
+                is_object($fixers) ? get_class($fixers) : gettype($fixers)
+            ));
+        }
+
+        foreach ($fixers as $fixer) {
+            $this->addCustomFixer($fixer);
+        }
+
+        return $this;
+    }
+
+    public function getCustomFixers()
+    {
+        return $this->customFixers;
+    }
+
+    public function hideProgress($hideProgress)
+    {
+        $this->hideProgress = $hideProgress;
+
+        return $this;
+    }
+
+    public function usingCache()
+    {
+        return $this->usingCache;
+    }
+
+    public function usingLinter()
+    {
+        return $this->usingLinter;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function setCacheFile($cacheFile)
+    {
+        $this->cacheFile = $cacheFile;
+
+        return $this;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getCacheFile()
+    {
+        return $this->cacheFile;
+    }
+
+    /**
+     * Set PHP executable.
+     *
+     * @param string|null $phpExecutable
+     *
+     * @return Config
+     */
+    public function setPhpExecutable($phpExecutable)
+    {
+        $this->phpExecutable = $phpExecutable;
+
+        return $this;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getPhpExecutable()
+    {
+        return $this->phpExecutable;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getRiskyAllowed()
+    {
+        return $this->isRiskyAllowed;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function setRiskyAllowed($isRiskyAllowed)
+    {
+        $this->isRiskyAllowed = $isRiskyAllowed;
+
+        return $this;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function setRules(array $rules)
+    {
+        $this->rules = $rules;
+
+        return $this;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getRules()
+    {
+        return $this->rules;
+    }
+}

+ 16 - 226
src/Config/Config.php

@@ -11,237 +11,27 @@
 
 namespace Symfony\CS\Config;
 
-use Symfony\CS\ConfigInterface;
-use Symfony\CS\Finder\DefaultFinder;
-use Symfony\CS\FinderInterface;
-use Symfony\CS\FixerInterface;
+use Symfony\CS\Config as BaseConfig;
 
 /**
  * @author Fabien Potencier <fabien@symfony.com>
  * @author Katsuhiro Ogawa <ko.fivestar@gmail.com>
+ *
+ * @deprecated
  */
-class Config implements ConfigInterface
+class Config extends BaseConfig
 {
-    protected $name;
-    protected $description;
-    protected $finder;
-    protected $fixers = array();
-    protected $dir;
-    protected $customFixers = array();
-    protected $usingCache = true;
-    protected $usingLinter = true;
-    protected $hideProgress = false;
-    protected $cacheFile = '.php_cs.cache';
-    protected $phpExecutable;
-    protected $isRiskyAllowed = false;
-    protected $rules = array('@PSR2' => true);
-
-    public function __construct($name = 'default', $description = 'A default configuration')
-    {
-        $this->name = $name;
-        $this->description = $description;
-        $this->finder = new DefaultFinder();
-    }
-
-    public static function create()
-    {
-        return new static();
-    }
-
-    public function setDir($dir)
-    {
-        $this->dir = $dir;
-
-        return $this;
-    }
-
-    public function setUsingCache($usingCache)
-    {
-        $this->usingCache = $usingCache;
-
-        return $this;
-    }
-
-    public function setUsingLinter($usingLinter)
-    {
-        $this->usingLinter = $usingLinter;
-
-        return $this;
-    }
-
-    public function getDir()
-    {
-        return $this->dir;
-    }
-
-    public function finder(\Traversable $finder)
-    {
-        $this->finder = $finder;
-
-        return $this;
-    }
-
-    public function getFinder()
-    {
-        if ($this->finder instanceof FinderInterface && $this->dir !== null) {
-            $this->finder->setDir($this->dir);
-        }
-
-        return $this->finder;
-    }
-
-    /**
-     * Set fixers.
-     *
-     * @param FixerInterface[] $fixers
-     *
-     * @return $this
-     */
-    public function fixers(array $fixers)
-    {
-        $this->fixers = $fixers;
-
-        return $this;
-    }
-
-    public function getFixers()
-    {
-        return $this->fixers;
-    }
-
-    public function getName()
-    {
-        return $this->name;
-    }
-
-    public function getDescription()
-    {
-        return $this->description;
-    }
-
-    public function getHideProgress()
-    {
-        return $this->hideProgress;
-    }
-
-    public function addCustomFixer(FixerInterface $fixer)
-    {
-        $this->customFixers[] = $fixer;
-
-        return $this;
-    }
-
-    public function addCustomFixers($fixers)
-    {
-        if (false === is_array($fixers) && false === $fixers instanceof \Traversable) {
-            throw new \InvalidArgumentException(sprintf(
-                'Argument must be an array or a Traversable, got "%s".',
-                is_object($fixers) ? get_class($fixers) : gettype($fixers)
-            ));
-        }
-
-        foreach ($fixers as $fixer) {
-            $this->addCustomFixer($fixer);
-        }
-
-        return $this;
-    }
-
-    public function getCustomFixers()
-    {
-        return $this->customFixers;
-    }
-
-    public function hideProgress($hideProgress)
-    {
-        $this->hideProgress = $hideProgress;
-
-        return $this;
-    }
-
-    public function usingCache()
-    {
-        return $this->usingCache;
-    }
-
-    public function usingLinter()
-    {
-        return $this->usingLinter;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function setCacheFile($cacheFile)
-    {
-        $this->cacheFile = $cacheFile;
-
-        return $this;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getCacheFile()
-    {
-        return $this->cacheFile;
-    }
-
-    /**
-     * Set PHP executable.
-     *
-     * @param string|null $phpExecutable
-     *
-     * @return Config
-     */
-    public function setPhpExecutable($phpExecutable)
-    {
-        $this->phpExecutable = $phpExecutable;
-
-        return $this;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getPhpExecutable()
-    {
-        return $this->phpExecutable;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getRiskyAllowed()
-    {
-        return $this->isRiskyAllowed;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function setRiskyAllowed($isRiskyAllowed)
-    {
-        $this->isRiskyAllowed = $isRiskyAllowed;
-
-        return $this;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function setRules(array $rules)
-    {
-        $this->rules = $rules;
-
-        return $this;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getRules()
-    {
-        return $this->rules;
+    public function __construct()
+    {
+        @trigger_error(
+            sprintf(
+                'The "%s" class is deprecated. You should stop using it, as it will soon be removed in 2.0 version. Use "%s" instead.',
+                __CLASS__,
+                'Symfony\CS\Config'
+            ),
+            E_USER_DEPRECATED
+        );
+
+        parent::__construct();
     }
 }

+ 7 - 1
src/Config/MagentoConfig.php

@@ -15,13 +15,19 @@ use Symfony\CS\Finder\MagentoFinder;
 
 /**
  * @author Myke Hines <myke@webhines.com>
+ *
+ * @deprecated
  */
 class MagentoConfig extends Config
 {
     public function __construct()
     {
         @trigger_error(
-            sprintf('The "%s" class is deprecated. You should stop using it, as it will soon be removed in 2.0 version.', __CLASS__),
+            sprintf(
+                'The "%s" class is deprecated. You should stop using it, as it will soon be removed in 2.0 version. Use "%s" instead.',
+                __CLASS__,
+                'Symfony\CS\Config'
+            ),
             E_USER_DEPRECATED
         );
 

+ 7 - 1
src/Config/Symfony23Config.php

@@ -15,13 +15,19 @@ use Symfony\CS\Finder\Symfony23Finder;
 
 /**
  * @author Fabien Potencier <fabien@symfony.com>
+ *
+ * @deprecated
  */
 class Symfony23Config extends Config
 {
     public function __construct()
     {
         @trigger_error(
-            sprintf('The "%s" class is deprecated. You should stop using it, as it will soon be removed in 2.0 version.', __CLASS__),
+            sprintf(
+                'The "%s" class is deprecated. You should stop using it, as it will soon be removed in 2.0 version. Use "%s" instead.',
+                __CLASS__,
+                'Symfony\CS\Config'
+            ),
             E_USER_DEPRECATED
         );
 

+ 7 - 7
src/Console/Command/FixCommand.php

@@ -19,7 +19,7 @@ use Symfony\Component\Console\Output\ConsoleOutputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\EventDispatcher\EventDispatcher;
 use Symfony\Component\Stopwatch\Stopwatch;
-use Symfony\CS\Config\Config;
+use Symfony\CS\Config;
 use Symfony\CS\ConfigInterface;
 use Symfony\CS\Console\ConfigurationResolver;
 use Symfony\CS\Console\Output\ProcessOutput;
@@ -194,12 +194,12 @@ The example below will add two fixers to the default list of PSR2 set fixers:
 
     <?php
 
-    \$finder = Symfony\CS\Finder\DefaultFinder::create()
+    \$finder = Symfony\CS\Finder::create()
         ->exclude('somedir')
         ->in(__DIR__)
     ;
 
-    return Symfony\CS\Config\Config::create()
+    return Symfony\CS\Config::create()
         ->setRules(array(
             '@PSR2' => true,
             'strict_param' => true,
@@ -215,12 +215,12 @@ The following example shows how to use all ``Symfony`` Fixers but the ``short_ta
 
     <?php
 
-    \$finder = Symfony\CS\Finder\DefaultFinder::create()
+    \$finder = Symfony\CS\Finder::create()
         ->exclude('somedir')
         ->in(__DIR__)
     ;
 
-    return Symfony\CS\Config\Config::create()
+    return Symfony\CS\Config::create()
         ->setRules(array(
             '@Symfony' => true,
             'short_tag' => false,
@@ -246,7 +246,7 @@ Cache can be disabled via ``--using-cache`` option or config file:
 
     <?php
 
-    return Symfony\CS\Config\Config::create()
+    return Symfony\CS\Config::create()
         ->setUsingCache(false)
     ;
 
@@ -256,7 +256,7 @@ Cache file can be specified via ``--cache-file`` option or config file:
 
     <?php
 
-    return Symfony\CS\Config\Config::create()
+    return Symfony\CS\Config::create()
         ->setCacheFile(__DIR__.'/.php_cs.cache')
     ;
 

+ 2 - 3
src/Console/ConfigurationResolver.php

@@ -12,7 +12,6 @@
 namespace Symfony\CS\Console;
 
 use Symfony\Component\Filesystem\Filesystem;
-use Symfony\CS\Config\Config;
 use Symfony\CS\ConfigInterface;
 use Symfony\CS\ConfigurationException\InvalidConfigurationException;
 use Symfony\CS\Fixer;
@@ -402,8 +401,8 @@ final class ConfigurationResolver
             $config = include $configFile;
 
             // verify that the config has an instance of Config
-            if (!$config instanceof Config) {
-                throw new InvalidConfigurationException(sprintf('The config file: "%s" does not return a "Symfony\CS\Config\Config" instance. Got: "%s".', $configFile, is_object($config) ? get_class($config) : gettype($config)));
+            if (!$config instanceof ConfigInterface) {
+                throw new InvalidConfigurationException(sprintf('The config file: "%s" does not return a "Symfony\CS\ConfigInterface" instance. Got: "%s".', $configFile, is_object($config) ? get_class($config) : gettype($config)));
             }
 
             $this->config = $config;

+ 75 - 0
src/Finder.php

@@ -0,0 +1,75 @@
+<?php
+
+/*
+ * This file is part of the PHP CS utility.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Symfony\CS;
+
+use Symfony\Component\Finder\Finder as BaseFinder;
+
+/**
+ * @author Fabien Potencier <fabien@symfony.com>
+ * @author Dariusz Rumiñski <dariusz.ruminski@gmail.com>
+ */
+class Finder extends BaseFinder implements FinderInterface
+{
+    public function __construct()
+    {
+        parent::__construct();
+
+        $this
+            ->files()
+            ->name('*.php')
+            ->name('*.phpt')
+            ->name('*.twig')
+            ->ignoreDotFiles(true)
+            ->ignoreVCS(true)
+            ->exclude('vendor')
+        ;
+
+        $files = $this->getFilesToExclude();
+
+        if (!empty($files)) {
+            $this->filter(
+                function (\SplFileInfo $file) use ($files) {
+                    return !in_array($file->getRelativePathname(), $files, true);
+                }
+            );
+        }
+    }
+
+    public function setDir($dir)
+    {
+        $this->in($this->getDirs($dir));
+    }
+
+    /**
+     * Gets the directories that needs to be scanned for files to validate.
+     *
+     * @param string $dir
+     *
+     * @return string[]
+     */
+    protected function getDirs($dir)
+    {
+        return array($dir);
+    }
+
+    /**
+     * Excludes files because modifying them would break.
+     *
+     * This is mainly useful for fixtures in unit tests.
+     *
+     * @return string[]
+     */
+    protected function getFilesToExclude()
+    {
+        return array();
+    }
+}

+ 15 - 49
src/Finder/DefaultFinder.php

@@ -11,65 +11,31 @@
 
 namespace Symfony\CS\Finder;
 
-use Symfony\Component\Finder\Finder;
-use Symfony\CS\FinderInterface;
+use Symfony\CS\Finder as BaseFinder;
 
 /**
  * @author Fabien Potencier <fabien@symfony.com>
+ *
+ * @deprecated
  */
-class DefaultFinder extends Finder implements FinderInterface
+class DefaultFinder extends BaseFinder
 {
     public function __construct()
     {
+        @trigger_error(
+            sprintf(
+                'The "%s" class is deprecated. You should stop using it, as it will soon be removed in 2.0 version. Use "%s" instead.',
+                __CLASS__,
+                'Symfony\CS\Finder'
+            ),
+            E_USER_DEPRECATED
+        );
+
         parent::__construct();
 
         $this
-            ->files()
-            ->name('*.php')
-            ->name('*.phpt')
-            ->name('*.twig')
-            ->ignoreDotFiles(true)
-            ->ignoreVCS(true)
-            ->exclude('vendor')
+            ->name('*.xml')
+            ->name('*.yml')
         ;
-
-        $files = $this->getFilesToExclude();
-
-        if (!empty($files)) {
-            $this->filter(
-                function (\SplFileInfo $file) use ($files) {
-                    return !in_array($file->getRelativePathname(), $files, true);
-                }
-            );
-        }
-    }
-
-    public function setDir($dir)
-    {
-        $this->in($this->getDirs($dir));
-    }
-
-    /**
-     * Gets the directories that needs to be scanned for files to validate.
-     *
-     * @param string $dir
-     *
-     * @return string[]
-     */
-    protected function getDirs($dir)
-    {
-        return array($dir);
-    }
-
-    /**
-     * Excludes files because modifying them would break.
-     *
-     * This is mainly useful for fixtures in unit tests.
-     *
-     * @return string[]
-     */
-    protected function getFilesToExclude()
-    {
-        return array();
     }
 }

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