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

EventSubscriber   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 35
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A onPrePatch() 0 7 2
A __construct() 0 4 1
A getSubscribedEvents() 0 4 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