SidebarMenuPresenter::getMenuWithDropDownWrapper()   A
last analyzed

Complexity

Conditions 5
Paths 16

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.2888
c 0
b 0
f 0
cc 5
nc 16
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Menus\Presenters;
6
7
use Illuminate\Support\Str;
8
use Rinvex\Menus\Models\MenuItem;
9
10
class SidebarMenuPresenter extends BasePresenter
11
{
12
    /**
13
     * Get open tag wrapper.
14
     *
15
     * @return string
16
     */
17
    public function getOpenTagWrapper(): string
18
    {
19
        return '<ul class="nav navbar-nav">';
20
    }
21
22
    /**
23
     * Get close tag wrapper.
24
     *
25
     * @return string
26
     */
27
    public function getCloseTagWrapper(): string
28
    {
29
        return '</ul>';
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function getDividerWrapper(): string
36
    {
37
        return '<li class="divider"></li>';
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function getHeaderWrapper(MenuItem $item): string
44
    {
45
        return '<li class="dropdown-header">'.($item->icon ? '<i class="'.$item->icon.'"></i> ' : '').$item->title.'</li>';
0 ignored issues
show
Documentation introduced by
The property icon does not exist on object<Rinvex\Menus\Models\MenuItem>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property title does not exist on object<Rinvex\Menus\Models\MenuItem>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
46
    }
47
48
    /**
49
     * Get menu tag without dropdown wrapper.
50
     *
51
     * @param \Rinvex\Menus\Models\MenuItem $item
52
     *
53
     * @return string
54
     */
55
    public function getMenuWithoutDropdownWrapper(MenuItem $item): string
56
    {
57
        return '<li class="'.($item->isActive() ? 'active' : '').'">
58
                    <a href="'.$item->getUrl().'" '.$item->getAttributes().'>
59
                        '.($item->icon ? '<i class="'.$item->icon.'"></i>' : '').'
0 ignored issues
show
Documentation introduced by
The property icon does not exist on object<Rinvex\Menus\Models\MenuItem>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
60
                        '.$item->title.'
0 ignored issues
show
Documentation introduced by
The property title does not exist on object<Rinvex\Menus\Models\MenuItem>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
61
                    </a>
62
                </li>';
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function getMenuWithDropDownWrapper(MenuItem $item, bool $specialSidebar = false): string
69
    {
70
        $id = Str::random();
71
72
        return $specialSidebar
73
            ? $this->getHeaderWrapper($item).$this->getChildMenuItems($item)
74
            : '<li class="panel panel-default'.($item->hasActiveOnChild() ? ' active' : '').'" id="dropdown">
75
                    <a data-toggle="collapse" href="#'.$id.'">
76
                        '.($item->icon ? '<i class="'.$item->icon.'"></i>' : '').'
0 ignored issues
show
Documentation introduced by
The property icon does not exist on object<Rinvex\Menus\Models\MenuItem>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
77
                        '.$item->title.' <span class="caret"></span>
0 ignored issues
show
Documentation introduced by
The property title does not exist on object<Rinvex\Menus\Models\MenuItem>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
78
                    </a>
79
                    <div id="'.$id.'" class="panel-collapse collapse'.($item->hasActiveOnChild() ? ' in' : '').'">
80
                        <div class="panel-body">
81
                            <ul class="nav navbar-nav">
82
                                '.$this->getChildMenuItems($item).'
83
                            </ul>
84
                        </div>
85
                    </div>
86
                </li>';
87
    }
88
89
    /**
90
     * Get multilevel menu wrapper.
91
     *
92
     * @param \Rinvex\Menus\Models\MenuItem $item
93
     *
94
     * @return string`
0 ignored issues
show
Documentation introduced by
The doc-type string` could not be parsed: Unknown type name "string`" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
95
     */
96
    public function getMultiLevelDropdownWrapper(MenuItem $item): string
97
    {
98
        return $this->getMenuWithDropDownWrapper($item);
99
    }
100
}
101