Column   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 186
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 19
lcom 2
cbo 1
dl 0
loc 186
rs 10
c 0
b 0
f 0

18 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setName() 0 5 1
A getName() 0 4 1
A setLabel() 0 5 1
A getLabel() 0 7 2
A setVisible() 0 5 1
A isVisible() 0 4 1
A setVisibleInForm() 0 5 1
A isVisibleInForm() 0 4 1
A setSortable() 0 5 1
A isSortable() 0 4 1
A addDecorator() 0 5 1
A clearDecorators() 0 5 1
A render() 0 4 1
A setFormElement() 0 5 1
A getFormElement() 0 4 1
A setInputFilterSpecification() 0 5 1
A getInputFilterSpecification() 0 4 1
1
<?php
2
3
namespace AtDataGrid\Column;
4
5
use AtDataGrid\Column\Decorator\DecoratorChain;
6
use AtDataGrid\Column\Decorator\DecoratorInterface;
7
use Zend\Form\Element;
8
use Zend\InputFilter\InputFilterProviderInterface;
9
10
class Column implements InputFilterProviderInterface
11
{
12
    protected $name;
13
    protected $label;
14
    protected $visible = true;
15
    protected $visibleInForm = true;
16
    protected $sortable = false;
17
    protected $formElement;
18
    protected $section;
19
    protected $inputFilterSpecification;
20
    protected $decorators;
21
22
    /**
23
     * Column constructor.
24
     * @param string $name
25
     */
26
    public function __construct($name)
27
    {
28
        $this->setName($name);
29
        $this->decorators = new DecoratorChain();
30
    }
31
32
    // METADATA
33
34
    /**
35
     * @param string $name
36
     * @return $this
37
     */
38
    public function setName($name)
39
    {
40
        $this->name = $name;
41
        return $this;
42
    }
43
44
    /**
45
     * @return mixed
46
     */
47
    public function getName()
48
    {
49
        return $this->name;
50
    }
51
52
    /**
53
     * @param string $name
54
     * @return $this
55
     */
56
    public function setLabel($name)
57
    {
58
    	$this->label = $name;
59
    	return $this;
60
    }
61
62
    /**
63
     * @return mixed
64
     */
65
    public function getLabel()
66
    {
67
        if (!$this->label) {
68
            return $this->name;
69
        }
70
        return $this->label;
71
    }
72
73
    /**
74
     * @param bool $value
75
     * @return $this
76
     */
77
    public function setVisible($value = true)
78
	{
79
		$this->visible = (bool)$value;
80
		return $this;
81
	}
82
83
    /**
84
     * @return bool
85
     */
86
    public function isVisible()
87
    {
88
        return $this->visible;
89
    }
90
91
    /**
92
     * @param $value
93
     * @return $this
94
     */
95
    public function setVisibleInForm($value)
96
    {
97
        $this->visibleInForm = $value;
98
        return $this;
99
    }
100
101
    /**
102
     * @return bool
103
     */
104
    public function isVisibleInForm()
105
    {
106
        return $this->visibleInForm;
107
    }
108
109
    /**
110
     * @param bool $value
111
     * @return $this
112
     */
113
    public function setSortable($value = true)
114
    {
115
        $this->sortable = (bool)$value;
116
        return $this;
117
    }
118
119
    /**
120
     * @return bool
121
     */
122
    public function isSortable()
123
    {
124
        return $this->sortable;
125
    }
126
127
    // RENDERING & DECORATORS
128
129
    /**
130
     * @param callable $decorator
131
     * @return $this
132
     */
133
    public function addDecorator(callable $decorator)
134
    {
135
        $this->decorators->attach($decorator);
136
        return $this;
137
    }
138
139
    /**
140
     * @return $this
141
     */
142
    public function clearDecorators()
143
    {
144
        $this->decorators = new DecoratorChain();
145
        return $this;
146
    }
147
148
    /**
149
     * @param $value
150
     * @param array $params
151
     * @return mixed
152
     */
153
    public function render($value, array $params = [])
154
    {
155
        return $this->decorators->decorate($value, $params);
156
    }
157
158
    /**
159
     * @param Element $formElement
160
     * @return $this
161
     */
162
    public function setFormElement(Element $formElement)
163
    {
164
    	$this->formElement = $formElement;
165
    	return $this;
166
    }
167
168
    /**
169
     * @return mixed
170
     */
171
    public function getFormElement()
172
    {
173
        return $this->formElement;
174
    }
175
176
    // INPUT FILTERS
177
178
    /**
179
     * @param $spec
180
     * @return $this
181
     */
182
    public function setInputFilterSpecification($spec)
183
    {
184
        $this->inputFilterSpecification = $spec;
185
        return $this;
186
    }
187
188
    /**
189
     * @return mixed
190
     */
191
    public function getInputFilterSpecification()
192
    {
193
        return $this->inputFilterSpecification;
194
    }
195
}