|
1 | 1 | #!/usr/bin/env php |
2 | 2 | <?php declare(strict_types = 1); |
3 | 3 |
|
| 4 | +// Usage: php infection-config.php [--source-directory='another/path'] [--mutator-class='Infection\Mutator\Removal\MethodCallRemoval'] [--timeout=60] |
| 5 | + |
4 | 6 | error_reporting(E_ALL & ~E_DEPRECATED); |
5 | 7 | ini_set('display_errors', 'stderr'); |
6 | 8 |
|
7 | | -$opts = getopt('', ['source-directory::', 'mutator-class::']); |
8 | | -if ($argc < 1) { |
9 | | - echo "Usage: php ". $argv[0] ." [--source-directory='another/path'] [--mutator-class='Infection\Mutator\Removal\MethodCallRemoval]'\n"; |
10 | | - exit(1); |
11 | | -} |
| 9 | +$opts = getopt('', ['source-directory::', 'mutator-class::', 'timeout::']); |
12 | 10 | $addSourceDirectories = (array) ($opts['source-directory'] ?? []); |
13 | 11 | $addMutatorClasses = (array) ($opts['mutator-class'] ?? []); |
| 12 | +$timeout = $opts['timeout'] ?? null; |
| 13 | + |
| 14 | +$defaults = file_get_contents(__DIR__.'/../resources/infection.json5'); |
| 15 | +if ($defaults === false) { |
| 16 | + throw new RuntimeException('Unable to read infection.json5'); |
| 17 | +} |
| 18 | +$decoded = json_decode($defaults); |
14 | 19 |
|
15 | | -$decoded = json_decode(file_get_contents(__DIR__.'/../resources/infection.json5')); |
16 | 20 | foreach($addSourceDirectories as $path) { |
17 | 21 | $decoded->source->directories[] = $path; |
18 | 22 | } |
19 | 23 | foreach($addMutatorClasses as $mutatorclass) { |
20 | 24 | $decoded->mutators->$mutatorclass = true; |
21 | 25 | } |
| 26 | +if ($timeout !== null) { |
| 27 | + $decoded->timeout = (int) $timeout; |
| 28 | +} |
22 | 29 |
|
23 | 30 | echo json_encode($decoded); |
24 | 31 |
|
|
0 commit comments