-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin.php
More file actions
59 lines (47 loc) · 1.73 KB
/
Copy pathPlugin.php
File metadata and controls
59 lines (47 loc) · 1.73 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
<?php
declare(strict_types=1);
namespace Xact\Phpstan\Dev;
use Composer\Composer;
use Composer\InstalledVersions;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
use Exception;
use Phar;
class Plugin implements PluginInterface
{
protected Composer $composer;
protected IOInterface $io;
public function activate(Composer $composer, IOInterface $io): void
{
$this->composer = $composer;
$this->io = $io;
$this->extractPHPStan();
}
// phpcs:ignore SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter
public function deactivate(Composer $composer, IOInterface $io): void
{
}
// phpcs:ignore SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter
public function uninstall(Composer $composer, IOInterface $io): void
{
}
public function extractPHPStan(): void
{
if (InstalledVersions::isInstalled('phpstan/phpstan') === false) {
throw new Exception("Could not find phpstan/phpstan, this should have been installed along with this package.");
}
$phpStanPath = (string)InstalledVersions::getInstallPath('phpstan/phpstan');
$pharPath = "{$phpStanPath}/phpstan.phar";
$extractPath = dirname(__DIR__) . "/phpstan";
if (!is_file($pharPath)) {
throw new Exception("phpstan/phpstan seems to be installed but could not find phpstan.phar.");
}
if (!file_exists($extractPath)) {
$phar = new Phar($pharPath);
$phar->extractTo($extractPath);
}
if (!file_exists($extractPath) || !file_exists("{$extractPath}/src")) {
throw new Exception("Could not find phpstan/src after extracting the .phar file.");
}
}
}