Completed
Push — master ( ae5e03...0447ee )
by Jeroen
10:35 queued 04:37
created

AdminList/ItemAction/SimpleItemAction.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\AdminListBundle\AdminList\ItemAction;
4
5
/**
6
 * The simple item action is a default implementation of the item action interface, this can be used
7
 * in very simple use cases.
8
 */
9
class SimpleItemAction implements ItemActionInterface
10
{
11
    /**
12
     * @var callable
13
     */
14
    private $routerGenerator;
15
16
    /**
17
     * @var string
18
     */
19
    private $icon;
20
21
    /**
22
     * @var string
23
     */
24
    private $label;
25
26
    /**
27
     * @var string|null
28
     */
29
    private $template;
30
31
    /**
32
     * @param callable $routerGenerator the generator used to generate the url of an item, when generating the item will
33
     *                                  be provided
34
     * @param string   $icon            The icon
35
     * @param string   $label           The label
36
     * @param string   $template        The template
37
     */
38 4
    public function __construct($routerGenerator, $icon, $label, $template = null)
39
    {
40 4
        $this->routerGenerator = $routerGenerator;
41 4
        $this->icon = $icon;
42 4
        $this->label = $label;
43 4
        $this->template = $template;
44 4
    }
45
46
    /**
47
     * @param mixed $item
48
     *
49
     * @return string
50
     */
51 3
    public function getUrlFor($item)
52
    {
53 3
        $routeGenerator = $this->routerGenerator;
54 3
        if (\is_callable($routeGenerator)) {
55 3
            return $routeGenerator($item);
56
        }
57
58 1
        return null;
59
    }
60
61
    /**
62
     * @param mixed $item
63
     *
64
     * @return string
65
     */
66 1
    public function getIconFor($item)
67
    {
68 1
        return $this->icon;
69
    }
70
71
    /**
72
     * @param mixed $item
73
     *
74
     * @return string
75
     */
76 1
    public function getLabelFor($item)
77
    {
78 1
        return $this->label;
79
    }
80
81
    /**
82
     * @return string
0 ignored issues
show
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
83
     */
84 1
    public function getTemplate()
85
    {
86 1
        return $this->template;
87
    }
88
}
89