forked from joomla-x/joomla-pythagoras
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoboFile.php
380 lines (337 loc) · 9.25 KB
/
RoboFile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<?php
/**
* Part of the Joomla CMS Build Environment
*
* @copyright Copyright (C) 2015 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
use Symfony\Component\Yaml\Yaml;
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
* @codingStandardsIgnoreStart
*/
class RoboFile extends \Robo\Tasks
{
private $config = [
'title' => "Joomla X (Pythagoras)",
'reports' => 'build/reports',
'apidocs' => 'build/docs',
'userdocs' => 'docs',
'toolcfg' => 'build/config'
];
private $ignoredDirs = [
'build',
'cache',
'docs',
'logs',
'tests',
'tmp',
'libraries/vendor',
];
private $ignoredFiles = [
'RoboFile.php',
];
private $vendorDir;
private $binDir;
use \Robo\Task\Testing\loadTasks;
/**
* RoboFile constructor.
*/
public function __construct()
{
$config = json_decode(file_get_contents(__DIR__ . '/composer.json'), true);
$this->vendorDir = isset($config['config']['vendor-dir']) ? __DIR__ . '/' . $config['config']['vendor-dir'] : $this->vendorDir = __DIR__ . '/vendor';
$this->binDir = $this->vendorDir . '/bin';
}
/**
* Measures the size and analyses the structure of the project.
*/
public function checkLoc()
{
$this->initReports();
$phploc = $this->taskExec($this->binDir . '/phploc')
->arg('--names-exclude=' . implode(',', $this->ignoredFiles))
->arg('--log-xml=' . $this->config['reports'] . '/phploc.xml');
foreach ($this->ignoredDirs as $dir)
{
$phploc->arg('--exclude=' . $dir);
}
$phploc->arg('.')->run();
}
/**
* Detects duplicate code.
*/
public function checkCpd()
{
$this->initReports();
$phploc = $this->taskExec($this->binDir . '/phpcpd')
->arg('--names-exclude=' . implode(',', $this->ignoredFiles))
->arg('--log-pmd=' . $this->config['reports'] . '/pmd-cpd.xml')
->arg('--fuzzy');
foreach ($this->ignoredDirs as $dir)
{
$phploc->arg('--exclude=' . $dir);
}
$phploc->arg('.')->run();
}
/**
* Performs static code analysis and calculates software metrics.
*/
public function checkDepend()
{
$this->initReports();
$pdepend = $this->taskExec($this->binDir . '/pdepend')
->arg('--dependency-xml=' . $this->config['reports'] . '/dependency.xml')
->arg('--jdepend-chart=' . $this->config['reports'] . '/jdepend.svg')
->arg('--jdepend-xml=' . $this->config['reports'] . '/jdepend.xml')
->arg('--overview-pyramid=' . $this->config['reports'] . '/pyramid.svg')
->arg('--summary-xml=' . $this->config['reports'] . '/summary.xml')
->arg('--ignore=' . implode(',', $this->ignoredDirs));
if (file_exists('' . $this->config['reports'] . '/coverage.xml'))
{
$pdepend->arg('--coverage-report=' . $this->config['reports'] . '/coverage.xml');
}
$pdepend->arg('.')->run();
}
/**
* Detects violations of the coding standard.
*/
public function checkStyle()
{
$this->initReports();
$this->taskStyle($this->binDir . '/phpcs')
->arg('--report=full')
->arg('--report-checkstyle=' . $this->config['reports'] . '/checkstyle.xml')
->run();
}
/**
* Sets the common parameters for CodeSniffer and CodeBeautifier
*
* @param string $bin One of 'phpcs' or 'phpcbf'
*
* @return \Robo\Task\Base\Exec
*/
private function taskStyle($bin)
{
return $this->taskExec($bin)
->arg('--standard=' . $this->vendorDir . '/greencape/coding-standards/src/Joomla')
->arg('--ignore=' . implode(',', $this->ignoredDirs))
->arg(__DIR__);
}
/**
* Generates `api`, `full`, and `style` documentation.
*/
public function document()
{
$this->documentApi();
$this->documentFull();
$this->documentStyle();
}
/**
* Generates API documentation.
*/
public function documentApi()
{
$this->initApiDocs();
$this->taskApiGen($this->binDir . '/apigen')
->arg('generate')
->config($this->config['toolcfg'] . '/apigen.api.yml')
->arg('--title "' . $this->config['title'] . ' API Documentation"')
->arg('--destination "' . $this->config['apidocs'] . '/api"')
->run();
}
/**
* Generates developer documentation.
* The documentation not only contains the API, but also protected members, and members marked as `@internal`.
*/
public function documentFull()
{
$this->initApiDocs();
$this->taskApiGen($this->binDir . '/apigen')
->arg('generate')
->config($this->config['toolcfg'] . '/apigen.full.yml')
->arg('--title="' . $this->config['title'] . ' Developer Documentation"')
->arg('--destination="' . $this->config['apidocs'] . '/full"')
->arg('--annotation-groups=package')
->run();
}
/**
* Generates a coding standard description.
*/
public function documentStyle()
{
$this->initApiDocs();
$this->taskStyle($this->binDir . '/phpcs')
->arg('--generator=Markdown')
->arg('> "' . $this->config['apidocs'] . '/coding-standard.md"')
->run();
}
/**
* Automatically corrects coding standard violations.
*/
public function fixStyle()
{
$this->taskStyle($this->binDir . '/phpcbf')
->run();
}
/**
* Creates a code listing with syntax highlighting and colored error-sections found by QA tools.
*/
public function reportCb()
{
$this->initReports();
$phpcb = $this->taskExec($this->binDir . '/phpcb')
->arg('--log "' . $this->config['reports'] . '"')
->arg('--source .')
->arg('--extensions ".php"')
->arg('--exclude "*.md"')
->arg('--exclude "*.dtd"')
->arg('--output "' . $this->config['reports'] . '/code"');
foreach (array_merge($this->ignoredDirs, $this->ignoredFiles) as $dir)
{
$phpcb->arg('--ignore ' . $dir);
}
$phpcb->run();
}
/**
* Creates a report with some software metrics.
*/
public function reportMetrics()
{
$this->initReports();
$this->taskExec($this->binDir . '/phpmetrics')
->arg('--config="' . $this->config['toolcfg'] . '/phpmetrics.yml"')
->arg('.')
->run();
}
/**
* Performs the tests from the `unit` suite.
*
* **Note**: The `unit` suite contains not only unit tests, but all tests,
* that can be conducted without external services like database or webserver.
*
* @param array $option
*
* @option $coverage Whether or not to generate a code coverage report
*/
public function testUnit($option = [
'coverage' => false
])
{
$this->test('unit', $option);
}
/**
* Performs the tests from the selected suite.
*
* @param string $suite The test suite to conduct
* @param array $option
*
* @option $coverage Whether or not to generate a code coverage report
*/
public function test($suite = 'all', $option = [
'coverage' => false
])
{
$this->initReports();
$tempConfigFile = $this->buildConfig($this->config['toolcfg'], $option['coverage']);
try
{
$codecept = $this->taskCodecept($this->binDir . '/codecept')
->configFile($tempConfigFile);
if ($suite != 'all')
{
$codecept->suite($suite);
}
if ($option['coverage'])
{
$codecept
->coverageXml('coverage.' . $suite . '.xml')
->coverageHtml('coverage');
}
$codecept->run();
} finally
{
$this->_remove($tempConfigFile);
}
}
/**
* @param $dir
* @param $enableCoverage
*
* @return string
*/
protected function buildConfig($dir, $enableCoverage)
{
$file = 'codeception.yml';
if (!file_exists($dir . '/' . $file))
{
$file = 'codeception.yml.dist';
}
$configFile = $dir . '/' . $file;
$config = Yaml::parse(file_get_contents($configFile));
$config['coverage']['enabled'] = $enableCoverage;
$config['coverage']['whitelist'] = [
'include' => [
'administrator/*.php',
'bin/*.php',
'cli/*.php',
'components/*.php',
'installation/*.php',
'layouts/*.php',
'libraries/incubator/*.php',
'modules/*.php',
'plugins/*.php',
],
];
$config['paths']['log'] = $this->config['reports'];
$tempConfigFile = 'codeception.yml';
file_put_contents($tempConfigFile, Yaml::dump($config));
return $tempConfigFile;
}
/**
* Performs the tests from the `acceptance` suite.
*
* **Note**: The `acceptance` suite contains all tests,
* that involve a browser.
*
* @param array $option
*
* @option $coverage Whether or not to generate a code coverage report
*/
public function testSystem($option = [
'coverage' => false
])
{
$this->test('acceptance', $option);
}
/**
* Disabled due to MD 2.4.3 internal problems
*/
protected function checkMd()
{
$this->initReports();
$this->taskExec($this->binDir . '/phpmd')
->arg(__DIR__)
->arg('xml')
->arg($this->config['toolcfg'] . '/phpmd.xml')
->arg('--reportfile=' . $this->config['reports'] . '/pmd.xml')
->arg('--exclude=' . implode(',', $this->ignoredDirs))
->run();
}
private function initApiDocs()
{
if (!file_exists($this->config['apidocs']))
{
$this->_mkdir($this->config['apidocs']);
}
}
private function initReports()
{
if (!file_exists($this->config['reports']))
{
$this->_mkdir($this->config['reports']);
}
}
}