Passed
Push — master ( e985e7...9cead0 )
by Chauncey
03:51
created

PrioritizableTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setPriority() 0 11 2
A priority() 0 4 1
1
<?php
2
3
namespace Charcoal\Ui;
4
5
use InvalidArgumentException;
6
7
/**
8
 * Provides an entity with a priority level or sorting index.
9
 *
10
 * Implementation of {@see \Charcoal\Ui\PrioritizableInterface}.
11
 */
12
trait PrioritizableTrait
13
{
14
    /**
15
     * Priority level of the entity.
16
     *
17
     * @var integer
18
     */
19
    private $priority = 0;
20
21
    /**
22
     * Set the entity's priority index.
23
     *
24
     * @param  integer $priority An index, for sorting.
25
     * @throws InvalidArgumentException If the priority is not an integer.
26
     * @return self
27
     */
28
    public function setPriority($priority)
29
    {
30
        if (!is_numeric($priority)) {
31
            throw new InvalidArgumentException(
32
                'Priority must be an integer'
33
            );
34
        }
35
36
        $this->priority = intval($priority);
37
        return $this;
38
    }
39
40
    /**
41
     * Retrieve the entity's priority index.
42
     *
43
     * @return integer
44
     */
45
    public function priority()
46
    {
47
        return $this->priority;
48
    }
49
}
50