1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Churn\Configuration; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @internal |
9
|
|
|
*/ |
10
|
|
|
abstract class Config |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var array<string> |
14
|
|
|
*/ |
15
|
|
|
protected $directoriesToScan = []; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var integer |
19
|
|
|
*/ |
20
|
|
|
protected $filesToShow = 10; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var float|null |
24
|
|
|
*/ |
25
|
|
|
protected $minScoreToShow = 0.1; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var float|null |
29
|
|
|
*/ |
30
|
|
|
protected $maxScoreThreshold = null; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var integer |
34
|
|
|
*/ |
35
|
|
|
protected $parallelJobs = 10; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $commitsSince = '10 years ago'; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var array<string> |
44
|
|
|
*/ |
45
|
|
|
protected $filesToIgnore = []; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var array<string> |
49
|
|
|
*/ |
50
|
|
|
protected $fileExtensions = ['php']; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var string |
54
|
|
|
*/ |
55
|
|
|
protected $vcs = 'git'; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var string|null |
59
|
|
|
*/ |
60
|
|
|
protected $cachePath = null; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var array<string> |
64
|
|
|
*/ |
65
|
|
|
protected $hooks = []; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var string|null |
69
|
|
|
*/ |
70
|
|
|
protected $path; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var array<int|string> |
74
|
|
|
*/ |
75
|
|
|
protected $unrecognizedKeys = []; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param string|null $path The path of the configuration file if any. |
79
|
|
|
*/ |
80
|
|
|
public function __construct(?string $path = null) |
81
|
|
|
{ |
82
|
|
|
$this->path = $path; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return array<int|string> The unrecognized keys. |
87
|
|
|
*/ |
88
|
|
|
public function getUnrecognizedKeys(): array |
89
|
|
|
{ |
90
|
|
|
return $this->unrecognizedKeys; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Return the path of the folder containing the configuration file. |
95
|
|
|
*/ |
96
|
|
|
public function getDirPath(): string |
97
|
|
|
{ |
98
|
|
|
return null === $this->path |
99
|
|
|
? (string) \getcwd() |
100
|
|
|
: \dirname($this->path); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Get the paths of directories to scan. |
105
|
|
|
* |
106
|
|
|
* @return array<string> |
107
|
|
|
*/ |
108
|
|
|
public function getDirectoriesToScan(): array |
109
|
|
|
{ |
110
|
|
|
return $this->directoriesToScan; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param array<string> $directoriesToScan Paths of directories to scan. |
115
|
|
|
*/ |
116
|
|
|
public function setDirectoriesToScan(array $directoriesToScan): void |
117
|
|
|
{ |
118
|
|
|
$this->directoriesToScan = $directoriesToScan; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Get the number of files to display in the results table. |
123
|
|
|
*/ |
124
|
|
|
public function getFilesToShow(): int |
125
|
|
|
{ |
126
|
|
|
return $this->filesToShow; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Get the minimum score a file need to display (ignored if null). |
131
|
|
|
*/ |
132
|
|
|
public function getMinScoreToShow(): ?float |
133
|
|
|
{ |
134
|
|
|
return $this->minScoreToShow; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Get the maximum score threshold. |
139
|
|
|
*/ |
140
|
|
|
public function getMaxScoreThreshold(): ?float |
141
|
|
|
{ |
142
|
|
|
return $this->maxScoreThreshold; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Get the number of parallel jobs to use to process the files. |
147
|
|
|
*/ |
148
|
|
|
public function getParallelJobs(): int |
149
|
|
|
{ |
150
|
|
|
return $this->parallelJobs; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param integer $parallelJobs Number of parallel jobs. |
155
|
|
|
*/ |
156
|
|
|
public function setParallelJobs(int $parallelJobs): void |
157
|
|
|
{ |
158
|
|
|
$this->parallelJobs = $parallelJobs; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Get how far back in the history to go to count commits. |
163
|
|
|
*/ |
164
|
|
|
public function getCommitsSince(): string |
165
|
|
|
{ |
166
|
|
|
return $this->commitsSince; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @return array<string> |
171
|
|
|
*/ |
172
|
|
|
public function getFilesToIgnore(): array |
173
|
|
|
{ |
174
|
|
|
return $this->filesToIgnore; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Get the file extensions to use when processing. |
179
|
|
|
* |
180
|
|
|
* @return array<string> |
181
|
|
|
*/ |
182
|
|
|
public function getFileExtensions(): array |
183
|
|
|
{ |
184
|
|
|
return $this->fileExtensions; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Get the version control system. |
189
|
|
|
*/ |
190
|
|
|
public function getVCS(): string |
191
|
|
|
{ |
192
|
|
|
return $this->vcs; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Get the cache file path. |
197
|
|
|
*/ |
198
|
|
|
public function getCachePath(): ?string |
199
|
|
|
{ |
200
|
|
|
return $this->cachePath; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Get the hooks. |
205
|
|
|
* |
206
|
|
|
* @return array<string> |
207
|
|
|
*/ |
208
|
|
|
public function getHooks(): array |
209
|
|
|
{ |
210
|
|
|
return $this->hooks; |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
|