ReloadBashConfigEvent::getBashConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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