123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- <?php
- declare(strict_types=1);
- /*
- * 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 string $cacheFile = '.php-cs-fixer.cache';
- /**
- * @var FixerInterface[]
- */
- private array $customFixers = [];
- /**
- * @var null|iterable<\SplFileInfo>
- */
- private ?iterable $finder = null;
- private string $format = 'txt';
- private bool $hideProgress = false;
- private string $indent = ' ';
- private bool $isRiskyAllowed = false;
- private string $lineEnding = "\n";
- private string $name;
- /**
- * @var null|string
- */
- private $phpExecutable;
- /**
- * @TODO: 4.0 - update to @PER
- *
- * @var array<string, array<string, mixed>|bool>
- */
- private array $rules = ['@PSR12' => true];
- private bool $usingCache = true;
- public function __construct(string $name = 'default')
- {
- $this->name = $name;
- }
- /**
- * {@inheritdoc}
- */
- public function getCacheFile(): string
- {
- return $this->cacheFile;
- }
- /**
- * {@inheritdoc}
- */
- public function getCustomFixers(): array
- {
- return $this->customFixers;
- }
- /**
- * @return Finder
- */
- public function getFinder(): iterable
- {
- if (null === $this->finder) {
- $this->finder = new Finder();
- }
- return $this->finder;
- }
- /**
- * {@inheritdoc}
- */
- public function getFormat(): string
- {
- return $this->format;
- }
- /**
- * {@inheritdoc}
- */
- public function getHideProgress(): bool
- {
- return $this->hideProgress;
- }
- /**
- * {@inheritdoc}
- */
- public function getIndent(): string
- {
- return $this->indent;
- }
- /**
- * {@inheritdoc}
- */
- public function getLineEnding(): string
- {
- return $this->lineEnding;
- }
- /**
- * {@inheritdoc}
- */
- public function getName(): string
- {
- return $this->name;
- }
- /**
- * {@inheritdoc}
- */
- public function getPhpExecutable(): ?string
- {
- return $this->phpExecutable;
- }
- /**
- * {@inheritdoc}
- */
- public function getRiskyAllowed(): bool
- {
- return $this->isRiskyAllowed;
- }
- /**
- * {@inheritdoc}
- */
- public function getRules(): array
- {
- return $this->rules;
- }
- /**
- * {@inheritdoc}
- */
- public function getUsingCache(): bool
- {
- return $this->usingCache;
- }
- /**
- * {@inheritdoc}
- */
- public function registerCustomFixers(iterable $fixers): ConfigInterface
- {
- foreach ($fixers as $fixer) {
- $this->addCustomFixer($fixer);
- }
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setCacheFile(string $cacheFile): ConfigInterface
- {
- $this->cacheFile = $cacheFile;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setFinder(iterable $finder): ConfigInterface
- {
- $this->finder = $finder;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setFormat(string $format): ConfigInterface
- {
- $this->format = $format;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setHideProgress(bool $hideProgress): ConfigInterface
- {
- $this->hideProgress = $hideProgress;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setIndent(string $indent): ConfigInterface
- {
- $this->indent = $indent;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setLineEnding(string $lineEnding): ConfigInterface
- {
- $this->lineEnding = $lineEnding;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setPhpExecutable(?string $phpExecutable): ConfigInterface
- {
- $this->phpExecutable = $phpExecutable;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setRiskyAllowed(bool $isRiskyAllowed): ConfigInterface
- {
- $this->isRiskyAllowed = $isRiskyAllowed;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setRules(array $rules): ConfigInterface
- {
- $this->rules = $rules;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function setUsingCache(bool $usingCache): ConfigInterface
- {
- $this->usingCache = $usingCache;
- return $this;
- }
- private function addCustomFixer(FixerInterface $fixer): void
- {
- $this->customFixers[] = $fixer;
- }
- }
|