Completed
Push — master ( aa9657...bb9832 )
by Sebastian
05:21
created

Hook   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 80
c 0
b 0
f 0
ccs 18
cts 18
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setEnabled() 0 4 1
A isEnabled() 0 4 1
A addAction() 0 4 1
A getActions() 0 4 1
A getJsonData() 0 8 2
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 SebastianFeldmann\CaptainHook\Config;
11
12
/**
13
 * Class Hook
14
 *
15
 * @package CaptainHook
16
 * @author  Sebastian Feldmann <[email protected]>
17
 * @link    https://github.com/sebastianfeldmann/captainhook
18
 * @since   Class available since Release 0.9.0
19
 */
20
class Hook
21
{
22
    /**
23
     * Is hook enabled
24
     *
25
     * @var bool
26
     */
27
    private $isEnabled = false;
28
29
    /**
30
     * List of Actions
31
     *
32
     * @var \SebastianFeldmann\CaptainHook\Config\Action[]
33
     */
34
    private $actions = [];
35
36
    /**
37
     * Hook constructor.
38
     *
39
     * @param bool $enabled
40
     */
41 39
    public function __construct(bool $enabled = false)
42
    {
43 39
        $this->isEnabled = $enabled;
44 39
    }
45
46
    /**
47
     * Enable or disable the hook.
48
     *
49
     * @param bool $enabled
50
     */
51 12
    public function setEnabled(bool $enabled)
52
    {
53 12
        $this->isEnabled = $enabled;
54 12
    }
55
56
    /**
57
     * Is this hook enabled.
58
     *
59
     * @return bool
60
     */
61 8
    public function isEnabled() : bool
62
    {
63 8
        return $this->isEnabled;
64
    }
65
66
    /**
67
     * Add an action to the list.
68
     *
69
     * @param \SebastianFeldmann\CaptainHook\Config\Action $action
70
     */
71 8
    public function addAction(Action $action)
72
    {
73 8
        $this->actions[] = $action;
74 8
    }
75
76
    /**
77
     * Return the action list.
78
     *
79
     * @return \SebastianFeldmann\CaptainHook\Config\Action[]
80
     */
81 8
    public function getActions() : array
82
    {
83 8
        return $this->actions;
84
    }
85
86
    /**
87
     * Return config data.
88
     *
89
     * @return array
90
     */
91 7
    public function getJsonData() : array
92
    {
93 7
        $config = ['enabled' => $this->isEnabled, 'actions' => []];
94 7
        foreach ($this->actions as $action) {
95 1
            $config['actions'][] = $action->getJsonData();
96
        }
97 7
        return $config;
98
    }
99
}
100