-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsplit-phpstan-baseline
More file actions
70 lines (57 loc) · 1.84 KB
/
split-phpstan-baseline
File metadata and controls
70 lines (57 loc) · 1.84 KB
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
#!/usr/bin/env php
<?php declare(strict_types=1);
namespace ShipMonk\PHPStan\Baseline;
use LogicException;
use ShipMonk\PHPStan\Baseline\Exception\ErrorException;
$autoloadFiles = [
__DIR__ . '/../../../autoload.php',
__DIR__ . '/../vendor/autoload.php',
];
foreach ($autoloadFiles as $autoloadFile) {
if (file_exists($autoloadFile)) {
require_once $autoloadFile;
break;
}
}
if (!isset($argv)) {
throw new LogicException('Missing $argv, check your register_argc_argv setting');
}
/**
* @return never
*/
function error(string $message): void
{
fwrite(STDERR, "\n! $message\n\n");
exit(1);
}
$providedOptions = getopt('', ['tabs', 'no-error-count'], $restIndex);
$args = array_slice($argv, $restIndex);
$loaderFile = $args[0] ?? null;
$indent = isset($providedOptions['tabs']) || in_array('--tabs', $args, true)
? "\t"
: ' ';
$includeCount = !(isset($providedOptions['no-error-count']) || in_array('--no-error-count', $args, true));
if ($loaderFile === null) {
error(
"Missing argument. Usage:\n".
" vendor/bin/phpstan --generate-baseline=baselines/_loader.neon && vendor/bin/split-phpstan-baseline baselines/_loader.neon"
);
}
if (!is_file($loaderFile)) {
error("Invalid argument, '$loaderFile' is not a file");
}
try {
$splitter = new BaselineSplitter($indent, $includeCount);
$writtenBaselines = $splitter->split($loaderFile);
foreach ($writtenBaselines as $writtenBaseline => $errorsCount) {
if ($errorsCount === 0) {
echo "Deleting baseline file $writtenBaseline\n";
} elseif ($errorsCount !== null) {
echo "Writing baseline file $writtenBaseline with $errorsCount errors\n";
} else {
echo "Writing baseline file $writtenBaseline\n";
}
}
} catch (ErrorException $e) {
error($e->getMessage());
}