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