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

Action   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 91
c 0
b 0
f 0
ccs 16
cts 16
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A getType() 0 4 1
A getAction() 0 4 1
A getOptions() 0 4 1
A getJsonData() 0 7 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 SebastianFeldmann\CaptainHook\Config;
11
12
/**
13
 * Class Action
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 Action
21
{
22
    /**
23
     * Action type
24
     *
25
     * @var string
26
     */
27
    private $type;
28
29
    /**
30
     * Action phpc lass or cli script
31
     *
32
     * @var string
33
     */
34
    private $action;
35
36
    /**
37
     * Map of options name => value
38
     *
39
     * @var \SebastianFeldmann\CaptainHook\Config\Options
40
     */
41
    private $options;
42
43
    /**
44
     * List of valid action types
45
     *
46
     * @var array
47
     */
48
    protected static $validTypes = ['php' => true, 'cli' => true];
49
50
    /**
51
     * Action constructor.
52
     *
53
     * @param  string $type
54
     * @param  string $action
55
     * @param  array  $options
56
     * @throws \Exception
57
     */
58 33
    public function __construct(string $type, string $action, array $options = [])
59
    {
60 33
        if (!isset(self::$validTypes[$type])) {
61 1
            throw new \Exception(sprintf('Invalid action type: %s', $type));
62
        }
63 32
        $this->type    = $type;
64 32
        $this->action  = $action;
65 32
        $this->options = new Options($options);
66 32
    }
67
68
    /**
69
     * Type getter.
70
     *
71
     * @return string
72
     */
73 1
    public function getType() : string
74
    {
75 1
        return $this->type;
76
    }
77
78
    /**
79
     * Action getter.
80
     *
81
     * @return string
82
     */
83 1
    public function getAction() : string
84
    {
85 1
        return $this->action;
86
    }
87
88
    /**
89
     * Return option map.
90
     *
91
     * @return \SebastianFeldmann\CaptainHook\Config\Options
92
     */
93 16
    public function getOptions() : Options
94
    {
95 16
        return $this->options;
96
    }
97
98
    /**
99
     * Return config data.
100
     *
101
     * @return array
102
     */
103 2
    public function getJsonData() : array
104
    {
105
        return [
106 2
            'action'  => $this->action,
107 2
            'options' => $this->options->getAll(),
108
        ];
109
    }
110
}
111