Passed
Pull Request — master (#9)
by ANTHONIUS
02:18
created

EventSubscriber::onPrePatch()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the dotfiles project.
5
 *
6
 *     (c) Anthonius Munthi <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Dotfiles\Plugins\NVM;
13
14
use Dotfiles\Core\Constant;
15
use Dotfiles\Core\DI\Parameters;
16
use Dotfiles\Core\Event\PatchEvent;
17
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
18
19
class EventSubscriber implements EventSubscriberInterface
20
{
21
    /**
22
     * @var Installer
23
     */
24
    private $installer;
25
26
    /**
27
     * @var Parameters
28
     */
29
    private $parameters;
30
31
    public function __construct(Parameters $parameters, Installer $installer)
32
    {
33
        $this->installer = $installer;
34
        $this->parameters = $parameters;
35
    }
36
37
    /**
38
     * @return array
39
     */
40
    public static function getSubscribedEvents(): array
41
    {
42
        return array(
43
            Constant::EVENT_PRE_PATCH => 'onPrePatch',
44
        );
45
    }
46
47
    public function onPrePatch(PatchEvent $patchEvent)
48
    {
49
        $parameters = $this->parameters;
50
51
        if (is_dir($parameters->get('nvm.install_dir'))) {
52
            $patch = $this->installer->getBashPatch();
53
            $patchEvent->addPatch('.bashrc', $patch);
54
        }
55
    }
56
}
57