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

MaxItemsTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setMaxSelectedItems() 0 9 3
A getMaxSelectedItems() 0 3 1
1
<?php
2
namespace Maknz\Slack;
3
4
use InvalidArgumentException;
5
6
trait MaxItemsTrait
7
{
8
    /**
9
     * Maximum number of selected items.
10
     *
11
     * @var int
12
     */
13
    protected $max_selected_items;
14
15
    /**
16
     * Get the maximum number of selected items.
17
     *
18
     * @return int
19
     */
20 6
    public function getMaxSelectedItems()
21
    {
22 6
        return $this->max_selected_items;
23
    }
24
25
    /**
26
     * Set the maximum number of selected items.
27
     *
28
     * @param int $maxSelectedItems
29
     *
30
     * @return $this
31
     *
32
     * @throws \InvalidArgumentException
33
     */
34 8
    public function setMaxSelectedItems($maxSelectedItems)
35
    {
36 8
        if (is_int($maxSelectedItems) && $maxSelectedItems >= 1) {
37 4
            $this->max_selected_items = $maxSelectedItems;
38
39 4
            return $this;
40
        }
41
42 4
        throw new InvalidArgumentException('The max selected items must be a positive integer');
43
    }
44
}
45