Passed
Push — master ( 8ede22...b3e0ce )
by Alexander
02:27
created

Confirmable   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

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