Completed
Push — master ( e52e2c...9baf6c )
by Oleg
08:13
created

HasAttributes   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 83.33%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 34
wmc 3
lcom 1
cbo 0
ccs 5
cts 6
cp 0.8333
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAttributes() 0 8 2
A buildAttributes() 0 4 1
1
<?php
2
namespace Malezha\Menu\Traits;
3
4
use Malezha\Menu\Contracts\Attributes;
5
6
/**
7
 * Class HasAttributes
8
 * @package Malezha\Menu\Traits
9
 */
10
trait HasAttributes
11
{
12
    /**
13
     * @var Attributes
14
     */
15
    protected $attributes;
16
17
    /**
18
     * Get attributes object.
19
     * If send \Closure option as parameter then returned callback result.
20
     * 
21
     * @param callable|null $callback
22
     * @return Attributes|mixed
23
     */
24 1
    public function getAttributes($callback = null)
25
    {
26 1
        if (is_callable($callback)) {
27
            return call_user_func($callback, $this->attributes);
28
        }
29
30 1
        return $this->attributes;
31
    }
32
33
    /**
34
     * Build attributes to html valid string
35
     * 
36
     * @param array $attributes
37
     * @return string
38
     */
39 2
    public function buildAttributes($attributes = [])
40
    {
41 2
        return $this->attributes->build($attributes);
42
    }
43
}