Passed
Pull Request — master (#13)
by Dmitriy
12:10
created

ComposerEventHandler::activate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
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 Plugin $plugin;
17
18
    /**
19
     * Returns list of events the plugin is subscribed to.
20
     *
21
     * @return array list of events
22
     */
23
    public static function getSubscribedEvents(): array
24
    {
25
        return [
26
            ScriptEvents::POST_AUTOLOAD_DUMP => [
27
                ['onPostAutoloadDump', 0],
28
            ],
29
        ];
30
    }
31
32
    public function activate(Composer $composer, IOInterface $io): void
33
    {
34
        $this->plugin = new Plugin($composer, $io);
35
    }
36
37
    public function onPostAutoloadDump(Event $event): void
38
    {
39
        require_once $event->getComposer()->getConfig()->get('vendor-dir') . '/autoload.php';
40
41
        $this->plugin->build();
42
    }
43
}
44