-
-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathvalidate-phpstan-version.php
More file actions
45 lines (35 loc) · 1.33 KB
/
validate-phpstan-version.php
File metadata and controls
45 lines (35 loc) · 1.33 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
<?php
declare(strict_types=1);
use Rector\Exception\ShouldNotHappenException;
use Rector\FileSystem\JsonFileSystem;
use Symfony\Component\Console\Command\Command;
require __DIR__ . '/../vendor/autoload.php';
$packageVersionResolver = new PackageVersionResolver();
$localPHPStanVersion = $packageVersionResolver->resolve(__DIR__ . '/../composer.json', 'phpstan/phpstan');
$downgradedPHPStanVersion = $packageVersionResolver->resolve(
__DIR__ . '/../build/target-repository/composer.json',
'phpstan/phpstan'
);
if ($localPHPStanVersion === $downgradedPHPStanVersion) {
echo '[OK] PHPStan version in local and downgraded composer.json are equal, good job!' . PHP_EOL;
exit(Command::SUCCESS);
}
echo sprintf(
'[ERROR] PHPStan version in local composer.json is "%s", in downgraded "%s".%sMake sure they are equal first.',
$localPHPStanVersion,
$downgradedPHPStanVersion,
PHP_EOL
) . PHP_EOL;
exit(Command::FAILURE);
final class PackageVersionResolver
{
public function resolve(string $composerFilePath, string $packageName): string
{
$composerJson = JsonFileSystem::readFilePath($composerFilePath);
$packageVersion = $composerJson['require'][$packageName] ?? null;
if ($packageVersion === null) {
throw new ShouldNotHappenException();
}
return $packageVersion;
}
}