-
-
Notifications
You must be signed in to change notification settings - Fork 440
Expand file tree
/
Copy pathadd-phpstan-self-replace.php
More file actions
28 lines (19 loc) · 904 Bytes
/
add-phpstan-self-replace.php
File metadata and controls
28 lines (19 loc) · 904 Bytes
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
<?php
// this is part of downgrade build
declare(strict_types=1);
use Nette\Utils\FileSystem;
use Nette\Utils\Json;
use PackageVersions\Versions;
require __DIR__ . '/../vendor/autoload.php';
if (! class_exists(Versions::class)) {
echo 'You need to run `composer require ocramius/package-versions` first' . PHP_EOL;
exit(1);
}
$composerJsonFileContents = FileSystem::read(__DIR__ . '/../composer.json');
$composerJson = Json::decode($composerJsonFileContents, forceArrays: true);
// result output is like: // 1.0.0@0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33
[$phpstanVersion] = explode('@', Versions::getVersion('phpstan/phpstan'));
$composerJson['replace']['phpstan/phpstan'] = $phpstanVersion;
$modifiedComposerJsonFileContents = Json::encode($composerJson, pretty: true);
FileSystem::write(__DIR__ . '/../composer.json', $modifiedComposerJsonFileContents, null);
echo 'Done!' . PHP_EOL;