Passed
Push — master ( b34030...56c38f )
by Sebastian
03:50
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 1
Bugs 0 Features 1
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 80
c 1
b 0
f 1
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 27
    public function __construct($enabled = false)
42
    {
43 27
        $this->isEnabled = $enabled;
44 27
    }
45
46
    /**
47
     * Enable or disable the hook.
48
     *
49
     * @param bool $enabled
50
     */
51 11
    public function setEnabled($enabled)
52
    {
53 11
        $this->isEnabled = $enabled;
54 11
    }
55
56
    /**
57
     * Is this hook enabled.
58
     *
59
     * @return bool
60
     */
61 8
    public function isEnabled()
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 7
    public function addAction(Action $action)
72
    {
73 7
        $this->actions[] = $action;
74 7
    }
75
76
    /**
77
     * Return the action list.
78
     *
79
     * @return \sebastianfeldmann\CaptainHook\Config\Action[]
80
     */
81 8
    public function getActions()
82
    {
83 8
        return $this->actions;
84
    }
85
86
    /**
87
     * Return config data.
88
     *
89
     * @return array
90
     */
91 7
    public function getJsonData()
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