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

ComposerEventHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 8
c 3
b 0
f 0
dl 0
loc 28
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 5 1
A onPostAutoloadDump() 0 5 1
A activate() 0 3 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 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