Completed
Push — master ( c91a26...385e70 )
by Shcherbak
02:45
created

CsConfiguration::createFixerConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
  namespace Funivan\Cs\Configuration;
4
5
  use Funivan\Cs\FileFinder\FinderFactory\FileFinderFactoryInterface;
6
  use Funivan\Cs\FileFinder\FinderParams;
7
8
  /**
9
   *
10
   */
11
  class CsConfiguration implements ConfigurationInterface {
12
13
    /**
14
     * @var FileFinderFactoryInterface|null
15
     */
16
    private $fileFinderFactory = null;
17
18
    /**
19
     * @var ToolConfigurationInterface[]
20
     */
21
    private $toolsConfiguration = [];
22
23
24
    /**
25
     * @return CsConfiguration
26
     */
27
    public static function createFixerConfiguration() {
28
      return (new CsConfiguration())->addToolsConfigurations(DefaultTools::getFixers());
29
    }
30
31
32
    /**
33
     * @return CsConfiguration
34
     */
35
    public static function createReviewConfiguration() {
36
      return (new CsConfiguration())->addToolsConfigurations(DefaultTools::getReviews());
37
    }
38
39
40
    /**
41
     * @inheritdoc
42
     */
43
    public function getFileFinderFactory(FinderParams $finderParams) {
44
      if ($this->fileFinderFactory === null) {
45
        throw new \Exception('Empty file finder factory');
46
      }
47
48
      return $this->fileFinderFactory->createFileFinder($finderParams);
49
    }
50
51
52
    /**
53
     * @param FileFinderFactoryInterface $fileFinder
54
     * @return $this
55
     */
56
    public function setFileFinderFactory(FileFinderFactoryInterface $fileFinder) {
57
      $this->fileFinderFactory = $fileFinder;
58
      return $this;
59
    }
60
61
62
    /**
63
     * @return ToolConfigurationInterface[]
64
     */
65
    public function getToolsConfiguration() {
66
      return $this->toolsConfiguration;
67
    }
68
69
70
    /**
71
     * @param ToolConfigurationInterface[] $toolsConfigurations
72
     * @return $this
73
     */
74
    public function addToolsConfigurations(array $toolsConfigurations) {
75
      foreach ($toolsConfigurations as $toolConfig) {
76
        $this->addToolConfiguration($toolConfig);
77
      }
78
      return $this;
79
    }
80
81
82
    /**
83
     * @param ToolConfigurationInterface $toolConfiguration
84
     * @return $this
85
     */
86
    public function addToolConfiguration(ToolConfigurationInterface $toolConfiguration) {
87
      $name = $toolConfiguration->getName();
88
      if (isset($this->toolsConfiguration[$name])) {
89
        throw new \InvalidArgumentException('Tool with name: ' . $name . ' already exist');
90
      }
91
92
      $this->toolsConfiguration[$name] = $toolConfiguration;
93
      return $this;
94
    }
95
96
97
    /**
98
     * @param string $name
99
     * @return ToolConfigurationInterface|null
100
     */
101
    public function getToolConfiguration($name) {
102
      if (isset($this->toolsConfiguration[$name])) {
103
        return $this->toolsConfiguration[$name];
104
      }
105
      return null;
106
    }
107
108
  }