Total Complexity | 9 |
Total Lines | 89 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | trait OptionsTrait |
||
8 | { |
||
9 | /** |
||
10 | * Options available within the block. |
||
11 | * |
||
12 | * @var \Maknz\Slack\CompositionObject\Option[] |
||
13 | */ |
||
14 | protected $options = []; |
||
15 | |||
16 | /** |
||
17 | * Get options available within the block. |
||
18 | * |
||
19 | * @return \Maknz\Slack\CompositionObject\Option[] |
||
20 | */ |
||
21 | 30 | public function getOptions() |
|
22 | { |
||
23 | 30 | return $this->options; |
|
24 | } |
||
25 | |||
26 | /** |
||
27 | * Get options available within the block in array format. |
||
28 | * |
||
29 | * @return array |
||
30 | */ |
||
31 | 11 | public function getOptionsAsArrays() |
|
32 | { |
||
33 | 11 | $options = []; |
|
34 | |||
35 | 11 | foreach ($this->getOptions() as $option) { |
|
36 | 11 | $options[] = $option->toArray(); |
|
37 | } |
||
38 | |||
39 | 11 | return $options; |
|
40 | } |
||
41 | |||
42 | /** |
||
43 | * Set options available within the block. |
||
44 | * |
||
45 | * @param array $options |
||
46 | * |
||
47 | * @return $this |
||
48 | * |
||
49 | * @throws \InvalidArgumentException |
||
50 | */ |
||
51 | 29 | public function setOptions(array $options) |
|
52 | { |
||
53 | 29 | $this->clearOptions(); |
|
54 | |||
55 | 29 | foreach ($options as $option) { |
|
56 | 29 | $this->addOption($option); |
|
57 | } |
||
58 | |||
59 | 27 | return $this; |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * Clear options available within the block. |
||
64 | * |
||
65 | * @return $this |
||
66 | */ |
||
67 | 29 | public function clearOptions() |
|
72 | } |
||
73 | |||
74 | /** |
||
75 | * Add an option to the block. |
||
76 | * |
||
77 | * @param mixed $option |
||
78 | * |
||
79 | * @return $this |
||
80 | * |
||
81 | * @throws \InvalidArgumentException |
||
82 | */ |
||
83 | 33 | public function addOption($option) |
|
98 |