HasAttributes::getAttributes()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2
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 4
    public function getAttributes($callback = null)
25
    {
26 4
        if (is_callable($callback)) {
27 1
            return call_user_func($callback, $this->attributes);
28
        }
29
30 3
        return $this->attributes;
31
    }
32
33
    /**
34
     * Build attributes to html valid string
35
     * 
36
     * @param array $attributes
37
     * @return string
38
     */
39 11
    public function buildAttributes($attributes = [])
40
    {
41 11
        return $this->attributes->build($attributes);
42
    }
43
}