Completed
Pull Request — master (#38)
by
unknown
03:25
created

Confirmable   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 41
ccs 8
cts 9
cp 0.8889
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setConfirm() 0 13 3
A getConfirm() 0 3 1
1
<?php
2
namespace Maknz\Slack\BlockElement;
3
4
use InvalidArgumentException;
5
use Maknz\Slack\BlockElement;
6
use Maknz\Slack\Object\Confirmation;
7
use Maknz\Slack\Object\Option;
8
9
abstract class Confirmable extends BlockElement
10
{
11
    /**
12
     * Confirmation object.
13
     *
14
     * @var \Maknz\Slack\Object\Confirmation
15
     */
16
    protected $confirm;
17
18
    /**
19
     * Get the confirmation object.
20
     *
21
     * @return \Maknz\Slack\Object\Confirmation
22
     */
23 12
    public function getConfirm()
24
    {
25 12
        return $this->confirm;
26
    }
27
28
    /**
29
     * Set the confirmation object.
30
     *
31
     * @param mixed $confirm
32
     *
33
     * @return Confirmable
34
     *
35
     * @throws \InvalidArgumentException
36
     */
37 9
    public function setConfirm($confirm)
38
    {
39 9
        if (is_array($confirm)) {
40 9
            $confirm = new Confirmation($confirm);
41
        }
42
43 9
        if ($confirm instanceof Confirmation) {
44 9
            $this->confirm = $confirm;
45
46 9
            return $this;
47
        }
48
49
        throw new InvalidArgumentException('Confirm must be a keyed array or ' . Confirmation::class . ' object');
50
    }
51
}
52