Completed
Pull Request — master (#47)
by Sebastian
01:45
created

Hook::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of CaptainHook.
4
 *
5
 * (c) Sebastian Feldmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace CaptainHook\App\Config;
11
12
/**
13
 * Class Hook
14
 *
15
 * @package CaptainHook
16
 * @author  Sebastian Feldmann <[email protected]>
17
 * @link    https://github.com/captainhookphp/captainhook
18
 * @since   Class available since Release 0.9.0
19
 * @internal
20
 */
21
class Hook
22
{
23
    /**
24
     * Hook name e.g. pre-commit
25
     *
26
     * @var string
27
     */
28
    private $name;
29
30
    /**
31
     * Is hook enabled
32
     *
33
     * @var bool
34
     */
35
    private $isEnabled = false;
36
37
    /**
38
     * List of Actions
39
     *
40
     * @var \CaptainHook\App\Config\Action[]
41
     */
42
    private $actions = [];
43
44
    /**
45
     * Hook constructor
46
     *
47
     * @param string $name
48
     * @param bool   $enabled
49
     */
50 59
    public function __construct(string $name, bool $enabled = false)
51
    {
52 59
        $this->name      = $name;
53 59
        $this->isEnabled = $enabled;
54 59
    }
55
56
    /**
57
     * Name getter
58
     *
59
     * @return string
60
     */
61 3
    public function getName() : string
62
    {
63 3
        return $this->name;
64
    }
65
66
    /**
67
     * Enable or disable the hook
68
     *
69
     * @param  bool $enabled
70
     * @return void
71
     */
72 23
    public function setEnabled(bool $enabled) : void
73
    {
74 23
        $this->isEnabled = $enabled;
75 23
    }
76
77
    /**
78
     * Is this hook enabled
79
     *
80
     * @return bool
81
     */
82 14
    public function isEnabled() : bool
83
    {
84 14
        return $this->isEnabled;
85
    }
86
87
    /**
88
     * Add an action to the list
89
     *
90
     * @param  \CaptainHook\App\Config\Action $action
91
     * @return void
92
     */
93 16
    public function addAction(Action $action) : void
94
    {
95 16
        $this->actions[] = $action;
96 16
    }
97
98
    /**
99
     * Return the action list
100
     *
101
     * @return \CaptainHook\App\Config\Action[]
102
     */
103 14
    public function getActions() : array
104
    {
105 14
        return $this->actions;
106
    }
107
108
    /**
109
     * Return config data
110
     *
111
     * @return array
112
     */
113 10
    public function getJsonData() : array
114
    {
115 10
        $config = ['enabled' => $this->isEnabled, 'actions' => []];
116 10
        foreach ($this->actions as $action) {
117 4
            $config['actions'][] = $action->getJsonData();
118
        }
119 10
        return $config;
120
    }
121
}
122