Config.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. /*
  3. * This file is part of the PHP CS utility.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Symfony\CS\Config;
  11. use Symfony\CS\ConfigInterface;
  12. use Symfony\CS\Finder\DefaultFinder;
  13. use Symfony\CS\FinderInterface;
  14. use Symfony\CS\FixerInterface;
  15. /**
  16. * @author Fabien Potencier <fabien@symfony.com>
  17. * @author Katsuhiro Ogawa <ko.fivestar@gmail.com>
  18. */
  19. class Config implements ConfigInterface
  20. {
  21. protected $name;
  22. protected $description;
  23. protected $finder;
  24. protected $level;
  25. protected $fixers;
  26. protected $dir;
  27. protected $customFixers;
  28. protected $usingCache = false;
  29. protected $usingLinter = true;
  30. protected $hideProgress = false;
  31. public function __construct($name = 'default', $description = 'A default configuration')
  32. {
  33. $this->name = $name;
  34. $this->description = $description;
  35. $this->level = FixerInterface::SYMFONY_LEVEL;
  36. $this->fixers = array();
  37. $this->finder = new DefaultFinder();
  38. $this->customFixers = array();
  39. }
  40. public static function create()
  41. {
  42. return new static();
  43. }
  44. public function setDir($dir)
  45. {
  46. $this->dir = $dir;
  47. }
  48. public function setUsingCache($usingCache)
  49. {
  50. $this->usingCache = $usingCache;
  51. return $this;
  52. }
  53. public function setUsingLinter($usingLinter)
  54. {
  55. $this->usingLinter = $usingLinter;
  56. return $this;
  57. }
  58. public function getDir()
  59. {
  60. return $this->dir;
  61. }
  62. public function finder(\Traversable $finder)
  63. {
  64. $this->finder = $finder;
  65. return $this;
  66. }
  67. public function getFinder()
  68. {
  69. if ($this->finder instanceof FinderInterface && $this->dir !== null) {
  70. $this->finder->setDir($this->dir);
  71. }
  72. return $this->finder;
  73. }
  74. public function level($level)
  75. {
  76. $this->level = $level;
  77. return $this;
  78. }
  79. public function getLevel()
  80. {
  81. return $this->level;
  82. }
  83. public function fixers($fixers)
  84. {
  85. $this->fixers = $fixers;
  86. return $this;
  87. }
  88. public function getFixers()
  89. {
  90. return $this->fixers;
  91. }
  92. public function getName()
  93. {
  94. return $this->name;
  95. }
  96. public function getDescription()
  97. {
  98. return $this->description;
  99. }
  100. public function getHideProgress()
  101. {
  102. return $this->hideProgress;
  103. }
  104. public function addCustomFixer(FixerInterface $fixer)
  105. {
  106. $this->customFixers[] = $fixer;
  107. return $this;
  108. }
  109. public function getCustomFixers()
  110. {
  111. return $this->customFixers;
  112. }
  113. public function hideProgress($hideProgress)
  114. {
  115. $this->hideProgress = $hideProgress;
  116. return $this;
  117. }
  118. public function usingCache()
  119. {
  120. return $this->usingCache;
  121. }
  122. public function usingLinter()
  123. {
  124. return $this->usingLinter;
  125. }
  126. }