ReloadBashConfigEvent   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 43
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addHeaderConfig() 0 9 2
A addFooterConfig() 0 6 2
A __construct() 0 3 1
A getBashConfig() 0 5 1
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\Bash\Event;
15
16
use Dotfiles\Core\Event\AbstractEvent;
17
use Psr\Log\LoggerInterface;
18
19
class ReloadBashConfigEvent extends AbstractEvent
20
{
21
    public const NAME = 'bash.reload_config';
22
23
    private $footer = array();
24
25
    private $header = array();
26
27
    /**
28
     * @var LoggerInterface
29
     */
30
    private $logger;
31
32
    public function __construct(LoggerInterface $logger)
33
    {
34
        $this->logger = $logger;
35
    }
36
37
    public function addFooterConfig($contents): void
38
    {
39
        if (!is_array($contents)) {
40
            $contents = array($contents);
41
        }
42
        $this->footer = array_merge($this->footer, $contents);
43
    }
44
45
    public function addHeaderConfig($contents): void
46
    {
47
        if (!is_array($contents)) {
48
            $contents = array($contents);
49
        }
50
        $this->header = array_merge($this->header, $contents);
51
        $this->logger->debug(
52
            'Added bash config',
53
            array('contents' => implode(PHP_EOL, $contents))
54
        );
55
    }
56
57
    public function getBashConfig()
58
    {
59
        $config = array_merge($this->header, $this->footer);
60
61
        return implode(PHP_EOL, $config);
62
    }
63
}
64