Icon   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 85
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getIconClass() 0 4 1
A setIconClass() 0 4 1
A hasIconClass() 0 8 2
A setIconLink() 0 4 1
A getIconLink() 0 4 1
A hasIconLink() 0 8 2
A getHtmlType() 0 12 3
1
<?php
2
3
namespace ZfcDatagrid\Column\Action;
4
5
class Icon extends AbstractAction
6
{
7
    protected $iconClass;
8
9
    protected $iconLink;
10
11
    /**
12
     * Set the icon class (CSS)
13
     * - used for HTML if provided, overwise the iconLink is used.
14
     *
15
     * @param string $name
16
     */
17
    public function setIconClass($name)
18
    {
19
        $this->iconClass = (string) $name;
20
    }
21
22
    /**
23
     * @return string
24
     */
25
    public function getIconClass()
26
    {
27
        return $this->iconClass;
28
    }
29
30
    /**
31
     * @return bool
32
     */
33
    public function hasIconClass()
34
    {
35
        if ($this->getIconClass() != '') {
36
            return true;
37
        }
38
39
        return false;
40
    }
41
42
    /**
43
     * Set the icon link (is used, if no icon class is provided).
44
     *
45
     * @param string $httpLink
46
     */
47
    public function setIconLink($httpLink)
48
    {
49
        $this->iconLink = (string) $httpLink;
50
    }
51
52
    /**
53
     * Get the icon link.
54
     *
55
     * @return string
56
     */
57
    public function getIconLink()
58
    {
59
        return $this->iconLink;
60
    }
61
62
    /**
63
     * @return bool
64
     */
65
    public function hasIconLink()
66
    {
67
        if ($this->getIconLink() != '') {
68
            return true;
69
        }
70
71
        return false;
72
    }
73
74
    /**
75
     * @return string
76
     */
77
    protected function getHtmlType()
78
    {
79
        if ($this->hasIconClass() === true) {
80
            // a css class is provided, so use it
81
            return '<i class="'.$this->getIconClass().'"></i>';
82
        } elseif ($this->hasIconLink() === true) {
83
            // no css class -> use the icon link instead
84
            return '<img src="'.$this->getIconLink().'" />';
85
        }
86
87
        throw new \InvalidArgumentException('Either a link or a class for the icon is required');
88
    }
89
}
90