-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddRootToExtensions.php
More file actions
47 lines (41 loc) · 1.49 KB
/
AddRootToExtensions.php
File metadata and controls
47 lines (41 loc) · 1.49 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
<?php
declare( strict_types=1 );
namespace Lipe\Lib\Phpstan;
use Composer\Script\Event;
use PHPStan\ExtensionInstaller\Plugin;
/**
* The plugin installer will not add the root package to the
* available plugins.
*
* When this package is installed as a dependency the plugin
* installer sets everything up automatically.
* When this package is the root package e.g., (installed as a standalone)
* this class adds itself as a local package and calls the original
* `process` method which generates the configuration.
*
* Without this class, the package cannot function as a standalone without
* `including` the `extension.neon` in every `phpstan.neon`.
*
* @author Mat Lipe
* @since December 2020
*
*/
class AddRootToExtensions {
public static function updatePlugins( Event $event ): void {
$composer = $event->getComposer();
$package = $composer->getPackage();
$extra = $package->getExtra();
$extra['phpstan']['includes'] = [ '../../../extension.neon' ];
$package->setExtra( $extra );
$io = $event->getIO();
try {
$composer->getRepositoryManager()->getLocalRepository()->addPackage( $package );
} catch ( \LogicException $exception ) {
$io->write( '<error>To use `lipemat/phpstan` as standalone, you must either install fresh without a lock file or run `composer update`.</error>' );
return;
}
$io->write( '<comment>Adding lipemat/phpstan-wordpress package as a phpstan extension.</comment>' );
// @phpstan-ignore-next-line
( new Plugin() )->process( $event );
}
}