EventSubscriber::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the dotfiles project.
7
 *
8
 *     (c) Anthonius Munthi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Dotfiles\Plugins\PHPBrew;
15
16
use Dotfiles\Core\Config\Config;
17
use Dotfiles\Core\Constant;
18
use Dotfiles\Core\Event\PatchEvent;
19
use Psr\Log\LoggerInterface;
20
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
21
22
class EventSubscriber implements EventSubscriberInterface
23
{
24
    /**
25
     * @var Config
26
     */
27
    private $config;
28
29
    /**
30
     * @var LoggerInterface
31
     */
32
    private $logger;
33
34
    public function __construct(Config $config, LoggerInterface $logger)
35
    {
36
        $this->config = $config;
37
        $this->logger = $logger;
38
    }
39
40
    public static function getSubscribedEvents()
41
    {
42
        return array(
43
            Constant::EVENT_PRE_PATCH => 'onPrePatchEvent',
44
        );
45
    }
46
47
    public function onPrePatchEvent(PatchEvent $event): void
48
    {
49
        $config = $this->config;
50
        if ($config->get('phpbrew.set_prompt')) {
51
            $event->addPatch('.bashrc', 'export PHPBREW_SET_PROMPT=1');
52
            $this->logger->debug('+phpbrew configured <comment>PHPBREW_USE_PROMPT</comment>');
53
        }
54
        if ($config->get('phpbrew.rc_enable')) {
55
            $event->addPatch('.bashrc', 'export PHPBREW_RC_ENABLE=1');
56
            $this->logger->debug('+phpbrew configured <comment>PHPBREW_RC_ENABLE</comment>');
57
        }
58
59
        $phpBrewScript = $config->get('dotfiles.home_dir').'/.phpbrew/bashrc';
60
        $event->addPatch('.bashrc', 'source "'.$phpBrewScript.'"');
61
    }
62
}
63