-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathvalidate-split-packages-phpstan.php
More file actions
73 lines (61 loc) · 1.93 KB
/
validate-split-packages-phpstan.php
File metadata and controls
73 lines (61 loc) · 1.93 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
71
72
73
#!/usr/bin/php -q
<?php
declare(strict_types=1);
/*
* Validate split packages through PHPStan.
*/
$options = [
__DIR__ . '/../vendor/autoload.php',
__DIR__ . '/vendor/autoload.php',
];
if (!empty($_SERVER['PWD'])) {
array_unshift($options, $_SERVER['PWD'] . '/vendor/autoload.php');
}
foreach ($options as $file) {
if (file_exists($file)) {
define('COMPOSER_INSTALL', $file);
break;
}
}
require COMPOSER_INSTALL;
$path = dirname(__DIR__) . DS . 'src' . DS;
$di = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS);
$iterator = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::LEAVES_ONLY);
/** @var array<\SplFileInfo> $iterator */
$iterator = new RegexIterator($iterator, '~/src/\w+/composer.json$~');
$packages = [];
$code = 0;
foreach ($iterator as $file) {
$filePath = $file->getPath();
$package = substr($filePath, strrpos($filePath, '/') + 1);
$packages[$filePath . '/'] = $package;
}
ksort($packages);
$phivePharsXml = simplexml_load_file(dirname(__FILE__, 2) . DS . '.phive' . DS . 'phars.xml');
$phpstanVersion = null;
foreach ($phivePharsXml->phar as $phar) {
if ($phar->attributes()->name == 'phpstan') {
$phpstanVersion = (string)$phar->attributes()->version;
break;
}
}
$composerCommand = 'composer require --dev phpstan/phpstan:' . $phpstanVersion;
$issues = [];
foreach ($packages as $path => $package) {
if (!file_exists($path . 'phpstan.neon.dist')) {
continue;
}
$exitCode = null;
exec(
'cd ' . $path . ' && ' . $composerCommand . ' && vendor/bin/phpstan analyze ./',
$output,
$exitCode
);
if ($exitCode !== 0) {
$code = $exitCode;
$issues[] = $package . ': ' . PHP_EOL . implode(PHP_EOL, $output);
}
exec('cd ' . $path . ' && rm composer.lock && rm -rf vendor && git checkout composer.json');
}
echo implode(PHP_EOL . PHP_EOL, $issues);
exit($code);