Completed
Push — master ( 994ddf...607686 )
by Michael
02:00
created

FetchesWeight::weight()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace Iatstuti\SimpleMenu\Traits;
4
5
/**
6
 * As the functionality is repeated, use a trait to
7
 * fetch the weight from the class' options array.
8
 *
9
 * @package    Iatstuti\SimpleMenu
10
 * @copyright  2016 IATSTUTI
11
 * @author     Michael Dyrynda <[email protected]>
12
 */
13
trait FetchesWeight
14
{
15
16
    abstract public function options($key = null);
17
18
    /**
19
     * If not null, set this menu's weight, else return the current value.
20
     *
21
     * @param  int|null $weight
22
     *
23
     * @return mixed
24
     */
25
    public function weight($weight = null)
26
    {
27
        if (is_null($weight)) {
28
            return (int) $this->options('weight');
29
        }
30
31
        $this->options['weight'] = (int) $weight;
32
33
        return $this;
34
    }
35
}
36