Passed
Push — master ( a7431d...f3f63b )
by Klaas
01:39 queued 18s
created

Plugin::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 2
cts 2
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Mediact\TestingSuite\Composer;
4
5
use Composer\Composer;
6
use Composer\EventDispatcher\EventSubscriberInterface;
7
use Composer\IO\IOInterface;
8
use Composer\Plugin\PluginInterface;
9
use Mediact\TestingSuite\Composer\Installer\InstallerInterface;
10
11
class Plugin implements PluginInterface, EventSubscriberInterface
12
{
13
    /** @var InstallerInterface[] */
14
    private $installers;
15
16
    /**
17
     * Constructor.
18
     *
19
     * @param InstallerInterface[] ...$installers
20
     */
21 1
    public function __construct(InstallerInterface ...$installers)
22
    {
23 1
        $this->installers = $installers;
24 1
    }
25
26
    /**
27
     * Apply plugin modifications to Composer.
28
     *
29
     * @param Composer    $composer
30
     * @param IOInterface $io
31
     *
32
     * @return void
33
     */
34 1
    public function activate(Composer $composer, IOInterface $io)
35
    {
36 1
        $this->addInstallers(
37 1
            ...include __DIR__ . '/installers.php'
38
        );
39 1
    }
40
41
    /**
42
     * Add installers.
43
     *
44
     * @param InstallerInterface[] ...$installers
45
     *
46
     * @return void
47
     */
48 1
    public function addInstallers(InstallerInterface ...$installers)
49
    {
50 1
        $this->installers = array_merge($this->installers, $installers);
51 1
    }
52
53
    /**
54
     * Run the installers.
55
     *
56
     * @return void
57
     */
58 1
    public function install()
59
    {
60 1
        foreach ($this->installers as $installer) {
61 1
            $installer->install();
62
        }
63 1
    }
64
65
    /**
66
     * Subscribe to post update and post install command.
67
     *
68
     * @return array
69
     */
70 1
    public static function getSubscribedEvents(): array
71
    {
72
        return [
73 1
            'post-install-cmd' => [
74
                'install'
75
            ],
76
            'post-update-cmd' => [
77
                'install'
78
            ]
79
        ];
80
    }
81
}
82