Conditions | 22 |
Paths | 4097 |
Total Lines | 109 |
Code Lines | 61 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
55 | public function __invoke(array $columns) |
||
56 | { |
||
57 | $return = []; |
||
58 | |||
59 | foreach ($columns as $column) { |
||
60 | /* @var $column \ZfcDatagrid\Column\AbstractColumn */ |
||
61 | |||
62 | $options = [ |
||
63 | 'name' => (string) $column->getUniqueId(), |
||
64 | 'index' => (string) $column->getUniqueId(), |
||
65 | 'label' => $this->translate((string) $column->getLabel()), |
||
66 | |||
67 | 'width' => $column->getWidth(), |
||
68 | 'hidden' => (bool) $column->isHidden(), |
||
69 | 'sortable' => (bool) $column->isUserSortEnabled(), |
||
70 | 'search' => (bool) $column->isUserFilterEnabled(), |
||
71 | ]; |
||
72 | |||
73 | /* |
||
74 | * Formatting |
||
75 | */ |
||
76 | $formatter = $this->getFormatter($column); |
||
77 | if ($formatter != '') { |
||
78 | $options['formatter'] = (string) $formatter; |
||
79 | } |
||
80 | |||
81 | $alignAlreadyDefined = false; |
||
82 | if ($column->hasStyles()) { |
||
83 | foreach ($column->getStyles() as $style) { |
||
84 | /** @var \ZfcDatagrid\Column\Style\Align $style */ |
||
85 | if (get_class($style) == 'ZfcDatagrid\Column\Style\Align') { |
||
86 | $options['align'] = $style->getAlignment(); |
||
87 | $alignAlreadyDefined = true; |
||
88 | break; |
||
89 | } |
||
90 | } |
||
91 | } |
||
92 | |||
93 | if (!$alignAlreadyDefined && $column->getType() instanceof Type\Number) { |
||
94 | $options['align'] = Column\Style\Align::$RIGHT; |
||
95 | } |
||
96 | |||
97 | /* |
||
98 | * Cellattr |
||
99 | */ |
||
100 | $rendererParameters = $column->getRendererParameters('jqGrid'); |
||
101 | if (isset($rendererParameters['cellattr'])) { |
||
102 | $options['cellattr'] = (string) $rendererParameters['cellattr']; |
||
103 | } |
||
104 | if (isset($rendererParameters['classes'])) { |
||
105 | $options['classes'] = (string) $rendererParameters['classes']; |
||
106 | } |
||
107 | |||
108 | /* |
||
109 | * Filtering |
||
110 | */ |
||
111 | $searchoptions = []; |
||
112 | $searchoptions['clearSearch'] = false; |
||
113 | if ($column->hasFilterSelectOptions() === true) { |
||
114 | $options['stype'] = 'select'; |
||
115 | $searchoptions['value'] = $column->getFilterSelectOptions(); |
||
116 | |||
117 | if ($column->hasFilterDefaultValue() === true) { |
||
118 | $searchoptions['defaultValue'] = $column->getFilterDefaultValue(); |
||
119 | } else { |
||
120 | $searchoptions['defaultValue'] = ''; |
||
121 | } |
||
122 | } elseif ($column->hasFilterDefaultValue() === true) { |
||
123 | $filter = new \ZfcDatagrid\Filter(); |
||
124 | $filter->setFromColumn($column, $column->getFilterDefaultValue()); |
||
125 | |||
126 | $searchoptions['defaultValue'] = $filter->getDisplayColumnValue(); |
||
127 | } |
||
128 | |||
129 | if (count($searchoptions) > 0) { |
||
130 | $options['searchoptions'] = $searchoptions; |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * Because with json_encode we get problems, it's custom made! |
||
135 | */ |
||
136 | $colModel = []; |
||
137 | foreach ($options as $key => $value) { |
||
138 | if (is_array($value)) { |
||
139 | $value = json_encode($value); |
||
140 | } elseif (is_bool($value)) { |
||
141 | if (true === $value) { |
||
142 | $value = 'true'; |
||
143 | } else { |
||
144 | $value = 'false'; |
||
145 | } |
||
146 | } elseif ('formatter' == $key) { |
||
147 | if (stripos($value, 'formatter') === false && stripos($value, 'function') === false) { |
||
148 | $value = '"'.$value.'"'; |
||
149 | } |
||
150 | } elseif ('cellattr' == $key) { |
||
|
|||
151 | // SKIP THIS |
||
152 | } else { |
||
153 | $value = '"'.$value.'"'; |
||
154 | } |
||
155 | |||
156 | $colModel[] = (string) $key.': '.$value; |
||
157 | } |
||
158 | |||
159 | $return[] = '{'.implode(',', $colModel).'}'; |
||
160 | } |
||
161 | |||
162 | return '['.implode(',', $return).']'; |
||
163 | } |
||
164 | |||
296 |
This check looks for the bodies of
elseif
statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
elseif
bodies can be removed. If you have an empty elseif but statements in theelse
branch, consider inverting the condition.