Completed
Push — master ( fa37fa...8c4a5b )
by ARCANEDEV
05:56
created

MenuItemAttributes   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 40
wmc 5
lcom 0
cbo 1
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 18 4
A __toString() 0 4 1
1
<?php namespace Arcanedev\Menus\Entities;
2
3
use Arcanedev\Menus\Contracts\Renderable;
4
use Arcanedev\Support\Collection;
5
6
/**
7
 * Class     MenuItemAttributes
8
 *
9
 * @package  Arcanedev\Menus\Entities
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class MenuItemAttributes extends Collection implements Renderable
13
{
14
    /* ------------------------------------------------------------------------------------------------
15
     |  Main Functions
16
     | ------------------------------------------------------------------------------------------------
17
     */
18
    /**
19
     * Render the instance to string.
20
     *
21
     * @return string
22
     */
23 24
    public function render()
24
    {
25 24
        $html = [];
26
27 24
        foreach ($this->all() as $key => $value) {
28 24
            if (is_null($value)) {
29 8
                continue;
30
            }
31
32 24
            if (is_numeric($key)) {
33 8
                $key = $value;
34 6
            }
35
36 24
            $html[] = $key . '="' . e($value) . '"';
37 18
        }
38
39 24
        return implode(' ', array_filter($html));
40
    }
41
42
    /**
43
     * Render the instance to string.
44
     *
45
     * @return string
46
     */
47 8
    public function __toString()
48
    {
49 8
        return $this->render();
50
    }
51
}
52