123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- <?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;
- use PhpCsFixer\Fixer\FixerInterface;
- /**
- * @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
- {
- private $cacheFile = '.php_cs.cache';
- private $customFixers = array();
- private $finder;
- private $format = 'txt';
- private $hideProgress = false;
- private $indent = ' ';
- private $isRiskyAllowed = false;
- private $lineEnding = "\n";
- private $name;
- private $phpExecutable;
- private $rules = array('@PSR2' => true);
- private $usingCache = true;
- public function __construct($name = 'default')
- {
- $this->name = $name;
- }
- /**
- * @return static
- */
- public static function create()
- {
- return new static();
- }
- /**
- * {@inheritdoc}
- */
- public function getCacheFile()
- {
- return $this->cacheFile;
- }
- /**
- * {@inheritdoc}
- */
- public function getCustomFixers()
- {
- return $this->customFixers;
- }
- /**
- * {@inheritdoc}
- */
- public function getFinder()
- {
- if (null === $this->finder) {
- $this->finder = new Finder();
- }
- return $this->finder;
- }
- /**
- * {@inheritdoc}
- */
- public function getFormat()
- {
- return $this->format;
- }
- /**
- * {@inheritdoc}
- */
- public function getHideProgress()
- {
- return $this->hideProgress;
- }
- /**
- * {@inheritdoc}
- */
- public function getIndent()
- {
- return $this->indent;
- }
- /**
- * {@inheritdoc}
- */
- public function getLineEnding()
- {
- return $this->lineEnding;
- }
- /**
- * {@inheritdoc}
- */
- public function getName()
- {
- return $this->name;
- }
- /**
- * {@inheritdoc}
- */
- public function getPhpExecutable()
- {
- return $this->phpExecutable;
- }
- /**
- * {@inheritdoc}
- */
- public function getRiskyAllowed()
- {
- return $this->isRiskyAllowed;
- }
- /**
- * {@inheritdoc}
- */
- public function getRules()
- {
- return $this->rules;
- }
- /**
- * {@inheritdoc}
- */
- public function getUsingCache()
- {
- return $this->usingCache;
- }
- /**
- * {@inheritdoc}
- */
- public function registerCustomFixers($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;
- }
- /**
- * {@inheritdoc}
- */
- public function setCacheFile($cacheFile)
- {
- $this->cacheFile = $cacheFile;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setFinder($finder)
- {
- if (false === is_array($finder) && false === $finder instanceof \Traversable) {
- throw new \InvalidArgumentException(sprintf(
- 'Argument must be an array or a Traversable, got "%s".',
- is_object($finder) ? get_class($finder) : gettype($finder)
- ));
- }
- $this->finder = $finder;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setFormat($format)
- {
- $this->format = $format;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setHideProgress($hideProgress)
- {
- $this->hideProgress = $hideProgress;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setIndent($indent)
- {
- $this->indent = $indent;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setLineEnding($lineEnding)
- {
- $this->lineEnding = $lineEnding;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setPhpExecutable($phpExecutable)
- {
- $this->phpExecutable = $phpExecutable;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setRiskyAllowed($isRiskyAllowed)
- {
- $this->isRiskyAllowed = $isRiskyAllowed;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setRules(array $rules)
- {
- $this->rules = $rules;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setUsingCache($usingCache)
- {
- $this->usingCache = $usingCache;
- return $this;
- }
- private function addCustomFixer(FixerInterface $fixer)
- {
- $this->customFixers[] = $fixer;
- }
- }
|