Completed
Push — master ( 90a8df...c30e79 )
by wen
13:14
created

HasNavigation::makePage()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 11
nc 3
nop 2
1
<?php
2
3
namespace Sco\Admin\Component\Concerns;
4
5
use KodiComponents\Navigation\Contracts\BadgeInterface;
6
use Sco\Admin\Navigation\Badge;
7
use Sco\Admin\Navigation\Page;
8
9
trait HasNavigation
10
{
11
    protected $icon;
12
13
    /**
14
     * {@inheritdoc}
15
     */
16
    public function getNavigation()
17
    {
18
        return $this->app['admin.navigation'];
0 ignored issues
show
Bug introduced by
The property app does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function addToNavigation($priority = 100, $badge = null)
25
    {
26
        $page = $this->makePage($priority, $badge);
27
        $this->getNavigation()->addPage($page);
28
        return $page;
29
    }
30
31
    /**
32
     * page
33
     *
34
     * @param int  $priority
35
     * @param null $badge
36
     *
37
     * @return \Sco\Admin\Navigation\Page
38
     */
39
    protected function makePage($priority = 100, $badge = null)
40
    {
41
        $page = new Page($this);
42
        $page->setPriority($priority)
43
            ->setIcon($this->getIcon())
44
            ->setAccessLogic(function () {
45
                return $this->isView();
0 ignored issues
show
Bug introduced by
It seems like isView() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
46
            });
47
48
        if ($badge) {
49
            if (!($badge instanceof BadgeInterface)) {
50
                $badge = new Badge($badge);
51
            }
52
            $page->addBadge($badge);
53
        }
54
55
        return $page;
56
    }
57
58
    /**
59
     * @param array $parameters
60
     *
61
     * @return string
62
     */
63
    public function getViewUrl(array $parameters = [])
64
    {
65
        array_unshift($parameters, $this->getName());
0 ignored issues
show
Bug introduced by
It seems like getName() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
66
67
        return route('admin.model.index', $parameters, false);
68
    }
69
70
    public function getIcon()
71
    {
72
        return $this->icon;
73
    }
74
75
    public function setIcon($value)
76
    {
77
        $this->icon = $value;
78
79
        return $this;
80
    }
81
}
82