Passed
Push — master ( eec14a...4028c5 )
by Alexander
02:26
created

FilterTrait::setFilter()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 13
ccs 7
cts 7
cp 1
crap 3
rs 10
1
<?php
2
namespace Maknz\Slack;
3
4
use InvalidArgumentException;
5
use Maknz\Slack\Object\Filter;
6
7
trait FilterTrait
8
{
9
    /**
10
     * A filter for the list of options.
11
     *
12
     * @var \Maknz\Slack\Object\Filter
13
     */
14
    protected $filter;
15
16
    /**
17
     * Get the filter for the list of options.
18
     *
19
     * @var \Maknz\Slack\Object\Filter
20
     */
21 6
    public function getFilter()
22
    {
23 6
        return $this->filter;
24
    }
25
26
    /**
27
     * Set the filter for the list of options.
28
     *
29
     * @param mixed $filter
30
     *
31
     * @return $this
32
     *
33
     * @throws \InvalidArgumentException
34
     */
35 6
    public function setFilter($filter)
36
    {
37 6
        if (is_array($filter)) {
38 5
            $filter = new Filter($filter);
39
        }
40
41 5
        if ($filter instanceof Filter) {
42 4
            $this->filter = $filter;
43
44 4
            return $this;
45
        }
46
47 1
        throw new InvalidArgumentException('The filter must be an instance of '.Filter::class.' or a keyed array');
48
    }
49
}
50