3
3
declare (strict_types=1 );
4
4
5
5
use Castor \Attribute \AsTask ;
6
+ use function Castor \context ;
6
7
use function Castor \io ;
7
8
use function Castor \run ;
8
9
@@ -27,32 +28,40 @@ function infect(int $minMsi = 0, int $minCoveredMsi = 0, bool $ci = false): void
27
28
$ command [] = '--logger-github ' ;
28
29
$ command [] = '-s ' ;
29
30
}
30
- $ environment = [
31
- 'XDEBUG_MODE ' => 'coverage ' ,
32
- ];
33
- run ($ command , environment: $ environment );
31
+ $ context = context ()
32
+ ->withEnvironment ([
33
+ 'XDEBUG_MODE ' => 'coverage ' ,
34
+ ])
35
+ ;
36
+ run ($ command , context: $ context );
34
37
}
35
38
36
39
#[AsTask(description: 'Run tests ' )]
37
40
function test (bool $ coverageHtml = false , bool $ coverageText = false , null |string $ group = null ): void
38
41
{
39
42
io ()->title ('Running tests ' );
40
43
$ command = ['php ' , 'vendor/bin/phpunit ' , '--color ' ];
41
- $ environment = [
42
- 'XDEBUG_MODE ' => 'off ' ,
43
- ];
44
+ $ context = context ()
45
+ ->withEnvironment ([
46
+ 'XDEBUG_MODE ' => 'off ' ,
47
+ ])
48
+ ;
44
49
if ($ coverageHtml ) {
45
50
$ command [] = '--coverage-html=build/coverage ' ;
46
- $ environment ['XDEBUG_MODE ' ] = 'coverage ' ;
51
+ $ context = $ context ->withEnvironment ([
52
+ 'XDEBUG_MODE ' => 'coverage ' ,
53
+ ]);
47
54
}
48
55
if ($ coverageText ) {
49
56
$ command [] = '--coverage-text ' ;
50
- $ environment ['XDEBUG_MODE ' ] = 'coverage ' ;
57
+ $ context = $ context ->withEnvironment ([
58
+ 'XDEBUG_MODE ' => 'coverage ' ,
59
+ ]);
51
60
}
52
61
if ($ group !== null ) {
53
62
$ command [] = sprintf ('--group=%s ' , $ group );
54
63
}
55
- run ($ command , environment : $ environment );
64
+ run ($ command , context : $ context );
56
65
}
57
66
58
67
#[AsTask(description: 'Coding standards check ' )]
@@ -64,16 +73,18 @@ function cs(
64
73
): void {
65
74
io ()->title ('Running coding standards check ' );
66
75
$ command = ['php ' , 'vendor/bin/ecs ' , 'check ' ];
67
- $ environment = [
68
- 'XDEBUG_MODE ' => 'off ' ,
69
- ];
76
+ $ context = context ()
77
+ ->withEnvironment ([
78
+ 'XDEBUG_MODE ' => 'off ' ,
79
+ ])
80
+ ;
70
81
if ($ fix ) {
71
82
$ command [] = '--fix ' ;
72
83
}
73
84
if ($ clearCache ) {
74
85
$ command [] = '--clear-cache ' ;
75
86
}
76
- run ($ command , environment : $ environment );
87
+ run ($ command , context : $ context );
77
88
}
78
89
79
90
#[AsTask(description: 'Running PHPStan ' )]
@@ -84,24 +95,28 @@ function stan(bool $baseline = false): void
84
95
if ($ baseline ) {
85
96
$ command [] = '--generate-baseline ' ;
86
97
}
87
- $ environment = [
88
- 'XDEBUG_MODE ' => 'off ' ,
89
- ];
90
- run ($ command , environment: $ environment );
98
+ $ context = context ()
99
+ ->withEnvironment ([
100
+ 'XDEBUG_MODE ' => 'off ' ,
101
+ ])
102
+ ;
103
+ run ($ command , context: $ context );
91
104
}
92
105
93
106
#[AsTask(description: 'Validate Composer configuration ' )]
94
107
function validate (): void
95
108
{
96
109
io ()->title ('Validating Composer configuration ' );
97
110
$ command = ['composer ' , 'validate ' , '--strict ' ];
98
- $ environment = [
99
- 'XDEBUG_MODE ' => 'off ' ,
100
- ];
101
- run ($ command , environment: $ environment );
111
+ $ context = context ()
112
+ ->withEnvironment ([
113
+ 'XDEBUG_MODE ' => 'off ' ,
114
+ ])
115
+ ;
116
+ run ($ command , context: $ context );
102
117
103
118
$ command = ['composer ' , 'dump-autoload ' , '--optimize ' , '--strict-psr ' ];
104
- run ($ command , environment : $ environment );
119
+ run ($ command , context : $ context );
105
120
}
106
121
107
122
/**
@@ -114,10 +129,12 @@ function checkLicenses(
114
129
io ()->title ('Checking licenses ' );
115
130
$ allowedExceptions = [];
116
131
$ command = ['composer ' , 'licenses ' , '-f ' , 'json ' ];
117
- $ environment = [
118
- 'XDEBUG_MODE ' => 'off ' ,
119
- ];
120
- $ result = run ($ command , environment: $ environment , quiet: true );
132
+ $ context = context ()
133
+ ->withEnvironment ([
134
+ 'XDEBUG_MODE ' => 'off ' ,
135
+ ])
136
+ ;
137
+ $ result = run ($ command , context: $ context , quiet: true );
121
138
if (! $ result ->isSuccessful ()) {
122
139
io ()->error ('Cannot determine licenses ' );
123
140
exit (1 );
@@ -177,30 +194,36 @@ function rector(
177
194
if ($ clearCache ) {
178
195
$ command [] = '--clear-cache ' ;
179
196
}
180
- $ environment = [
181
- 'XDEBUG_MODE ' => 'off ' ,
182
- ];
183
- run ($ command , environment: $ environment );
197
+ $ context = context ()
198
+ ->withEnvironment ([
199
+ 'XDEBUG_MODE ' => 'off ' ,
200
+ ])
201
+ ;
202
+ run ($ command , context: $ context );
184
203
}
185
204
186
205
#[AsTask(description: 'Run Rector ' )]
187
206
function deptrac (): void
188
207
{
189
208
io ()->title ('Running Rector ' );
190
209
$ command = ['php ' , 'vendor/bin/deptrac ' , 'analyse ' , '--fail-on-uncovered ' , '--no-cache ' ];
191
- $ environment = [
192
- 'XDEBUG_MODE ' => 'off ' ,
193
- ];
194
- run ($ command , environment: $ environment );
210
+ $ context = context ()
211
+ ->withEnvironment ([
212
+ 'XDEBUG_MODE ' => 'off ' ,
213
+ ])
214
+ ;
215
+ run ($ command , context: $ context );
195
216
}
196
217
197
218
#[AsTask(description: 'Run Linter ' )]
198
219
function lint (): void
199
220
{
200
221
io ()->title ('Running Linter ' );
201
222
$ command = ['composer ' , 'exec ' , '-- ' , 'parallel-lint ' , __DIR__ . '/src/ ' , __DIR__ . '/tests/ ' ];
202
- $ environment = [
203
- 'XDEBUG_MODE ' => 'off ' ,
204
- ];
205
- run ($ command , environment: $ environment );
223
+ $ context = context ()
224
+ ->withEnvironment ([
225
+ 'XDEBUG_MODE ' => 'off ' ,
226
+ ])
227
+ ;
228
+ run ($ command , context: $ context );
206
229
}
0 commit comments