ComposerEventHandler   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 3
b 0
f 0
dl 0
loc 40
ccs 0
cts 9
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A uninstall() 0 2 1
A getSubscribedEvents() 0 5 1
A deactivate() 0 2 1
A onPostAutoloadDump() 0 6 1
A activate() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Composer\Config;
6
7
use Composer\Composer;
8
use Composer\EventDispatcher\EventSubscriberInterface;
9
use Composer\IO\IOInterface;
10
use Composer\Plugin\PluginInterface;
11
use Composer\Script\Event;
12
use Composer\Script\ScriptEvents;
13
14
final class ComposerEventHandler implements PluginInterface, EventSubscriberInterface
15
{
16
    private Composer $composer;
17
    private IOInterface $io;
18
19
    /**
20
     * Returns list of events the plugin is subscribed to.
21
     *
22
     * @return array list of events
23
     */
24
    public static function getSubscribedEvents(): array
25
    {
26
        return [
27
            ScriptEvents::POST_AUTOLOAD_DUMP => [
28
                ['onPostAutoloadDump', 0],
29
            ],
30
        ];
31
    }
32
33
    public function activate(Composer $composer, IOInterface $io): void
34
    {
35
        $this->composer = $composer;
36
        $this->io = $io;
37
    }
38
39
    public function onPostAutoloadDump(Event $event): void
40
    {
41
        require_once $event->getComposer()->getConfig()->get('vendor-dir') . '/autoload.php';
42
43
        $plugin = new Plugin($this->composer, $this->io);
44
        $plugin->build();
45
    }
46
47
    public function deactivate(Composer $composer, IOInterface $io): void
48
    {
49
        // do nothing
50
    }
51
52
    public function uninstall(Composer $composer, IOInterface $io): void
53
    {
54
        // do nothing
55
    }
56
}
57