PatchEvent::addPatch()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
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\Core\Event;
15
16
class PatchEvent extends AbstractEvent
17
{
18
    public const NAME = 'dotfiles.patch';
19
20
    /**
21
     * @var array
22
     */
23
    private $patches;
24
25
    public function __construct(array $patches)
26
    {
27
        $this->patches = $patches;
28
    }
29
30
    public function addPatch($target, $patch): void
31
    {
32
        if (!isset($this->patches[$target])) {
33
            $this->patches[$target] = array();
34
        }
35
        $this->patches[$target][] = $patch;
36
    }
37
38
    /**
39
     * @return array
40
     */
41
    public function getPatches(): array
42
    {
43
        return $this->patches;
44
    }
45
46
    /**
47
     * Override current patch.
48
     *
49
     * @param string $relativePathName
50
     * @param array  $value
51
     */
52
    public function setPatch(string $relativePathName, array $value): void
53
    {
54
        $this->patches[$relativePathName] = $value;
55
    }
56
}
57