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

FilterTrait   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 setFilter() 0 13 3
A getFilter() 0 3 1
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