Completed
Push — master ( 3b8fc6...fa37fa )
by ARCANEDEV
10:04
created

MenuItemAttributes::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.125

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 4
cp 0.5
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1.125
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 15
    public function render()
24
    {
25 15
        $html = [];
26
27 15
        foreach ($this->all() as $key => $value) {
28 15
            if (is_null($value)) {
29 5
                continue;
30
            }
31
32 15
            if (is_numeric($key)) {
33 5
                $key = $value;
34 5
            }
35
36 15
            $html[] = $key . '="' . e($value) . '"';
37 15
        }
38
39 15
        return implode(' ', array_filter($html));
40
    }
41
42
    /**
43
     * Render the instance to string.
44
     *
45
     * @return string
46
     */
47 5
    public function __toString()
48
    {
49 5
        return $this->render();
50
    }
51
}
52