-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
castor.php
106 lines (98 loc) · 2.77 KB
/
castor.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
<?php
declare(strict_types=1);
use Castor\Attribute\AsTask;
use function Castor\io;
use function Castor\run;
#[AsTask(description: 'Run mutation testing')]
function infect(int $minMsi = 0, int $minCoveredMsi = 0, bool $ci = false): void
{
io()->title('Running infection');
$nproc = run('nproc', quiet: true);
if (! $nproc->isSuccessful()) {
io()->error('Cannot determine the number of processors');
return;
}
$threads = (int) $nproc->getOutput();
$command = [
'php',
'vendor/bin/infection',
sprintf('--min-msi=%s', $minMsi),
sprintf('--min-covered-msi=%s', $minCoveredMsi),
sprintf('--threads=%s', $threads),
];
if ($ci) {
$command[] = '--logger-github';
$command[] = '-s';
}
$environment = [
'XDEBUG_MODE' => 'coverage',
];
run($command, environment: $environment);
}
#[AsTask(description: 'Run tests')]
function test(bool $coverageHtml = false, bool $coverageText = false, null|string $group = null): void
{
io()->title('Running tests');
$command = ['php', 'vendor/bin/phpunit', '--color'];
$environment = [
'XDEBUG_MODE' => 'off',
];
if ($coverageHtml) {
$command[] = '--coverage-html=build/coverage';
$environment['XDEBUG_MODE'] = 'coverage';
}
if ($coverageText) {
$command[] = '--coverage-text';
$environment['XDEBUG_MODE'] = 'coverage';
}
if ($group !== null) {
$command[] = sprintf('--group=%s', $group);
}
run($command, environment: $environment);
}
#[AsTask(description: 'Coding standards check')]
function cs(bool $fix = false): void
{
io()->title('Running coding standards check');
$command = ['php', 'vendor/bin/ecs', 'check'];
$environment = [
'XDEBUG_MODE' => 'off',
];
if ($fix) {
$command[] = '--fix';
}
run($command, environment: $environment);
}
#[AsTask(description: 'Running PHPStan')]
function stan(): void
{
io()->title('Running PHPStan');
$command = ['php', 'vendor/bin/phpstan', 'analyse'];
$environment = [
'XDEBUG_MODE' => 'off',
];
run($command, environment: $environment);
}
#[AsTask(description: 'Validate Composer configuration')]
function validate(): void
{
io()->title('Validating Composer configuration');
$command = ['composer', 'validate'];
$environment = [
'XDEBUG_MODE' => 'off',
];
run($command, environment: $environment);
}
#[AsTask(description: 'Run Rector')]
function rector(bool $fix = false): void
{
io()->title('Running Rector');
$command = ['php', 'vendor/bin/rector', 'process', '--ansi'];
if (! $fix) {
$command[] = '--dry-run';
}
$environment = [
'XDEBUG_MODE' => 'off',
];
run($command, environment: $environment);
}