Completed
Push — master ( d7f072...e80481 )
by Shcherbak
05:37
created

CsConfiguration   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 0 Features 2
Metric Value
c 4
b 0
f 2
dl 0
loc 110
wmc 13
lcom 2
cbo 3
ccs 0
cts 44
cp 0
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A createFixerConfiguration() 0 3 1
A createReviewConfiguration() 0 3 1
A getFileFinderFactory() 0 7 2
A setFileFinderFactory() 0 4 1
A getTools() 0 3 1
A addTools() 0 6 2
A addTool() 0 9 2
A setTool() 0 5 1
A getTool() 0 7 2
1
<?php
2
3
  namespace Funivan\Cs\Configuration;
4
5
  use Funivan\Cs\FileFinder\FinderFactory\FileFinderFactoryInterface;
6
  use Funivan\Cs\FileFinder\FinderParams;
7
  use Funivan\Cs\FileTool\FileTool;
8
9
  /**
10
   * @author Ivan Shcherbak <[email protected]> 2016
11
   */
12
  class CsConfiguration implements ConfigurationInterface {
13
14
    /**
15
     * @var FileFinderFactoryInterface|null
16
     */
17
    private $fileFinderFactory = null;
18
19
    /**
20
     * @var FileTool[]
21
     */
22
    private $tools = [];
23
24
25
    /**
26
     * @return CsConfiguration
27
     */
28
    public static function createFixerConfiguration() {
29
      return (new CsConfiguration())->addTools(DefaultTools::getFixers());
30
    }
31
32
33
    /**
34
     * @return CsConfiguration
35
     */
36
    public static function createReviewConfiguration() {
37
      return (new CsConfiguration())->addTools(DefaultTools::getReviews());
38
    }
39
40
41
    /**
42
     * @inheritdoc
43
     */
44
    public function getFileFinderFactory(FinderParams $finderParams) {
45
      if ($this->fileFinderFactory === null) {
46
        throw new \Exception('Empty file finder factory');
47
      }
48
49
      return $this->fileFinderFactory->createFileFinder($finderParams);
50
    }
51
52
53
    /**
54
     * @param FileFinderFactoryInterface $fileFinder
55
     * @return $this
56
     */
57
    public function setFileFinderFactory(FileFinderFactoryInterface $fileFinder) {
58
      $this->fileFinderFactory = $fileFinder;
59
      return $this;
60
    }
61
62
63
    /**
64
     * @return FileTool[]
65
     */
66
    public function getTools() {
67
      return $this->tools;
68
    }
69
70
71
    /**
72
     * @param FileTool[] $fileTools
73
     * @return $this
74
     */
75
    public function addTools(array $fileTools) {
76
      foreach ($fileTools as $toolConfig) {
77
        $this->addTool($toolConfig);
78
      }
79
      return $this;
80
    }
81
82
83
    /**
84
     * @param FileTool $fileTool
85
     * @return $this
86
     */
87
    public function addTool(FileTool $fileTool) {
88
      $name = $fileTool->getName();
89
      if (isset($this->tools[$name])) {
90
        throw new \InvalidArgumentException('Tool with name: ' . $name . ' already exist');
91
      }
92
93
      $this->tools[$name] = $fileTool;
94
      return $this;
95
    }
96
97
98
    /**
99
     * @param FileTool $fileTool
100
     * @return $this
101
     */
102
    public function setTool(FileTool $fileTool) {
103
      $name = $fileTool->getName();
104
      $this->tools[$name] = $fileTool;
105
      return $this;
106
    }
107
108
109
    /**
110
     * @param string $name
111
     * @return FileTool|null
112
     */
113
    public function getTool($name) {
114
      if (isset($this->tools[$name])) {
115
        return $this->tools[$name];
116
      }
117
118
      return null;
119
    }
120
121
  }