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

FetchesWeight   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 23
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
options() 0 1 ?
A weight() 0 10 2
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