SimpleItemAction   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 3
cbo 0
dl 0
loc 80
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getUrlFor() 0 9 2
A getIconFor() 0 4 1
A getLabelFor() 0 4 1
A getTemplate() 0 4 1
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
0 ignored issues
show
Documentation introduced by
Should the type for parameter $template not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
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
Documentation introduced by
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