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
|
|
|
} |