Conditions | 27 |
Paths | 691 |
Total Lines | 91 |
Code Lines | 63 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 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 |
||
108 | public static function extractClassesFromFile($filename) |
||
109 | { |
||
110 | // @TODO probably break this into multiple functions |
||
111 | if (!is_readable($filename)) { |
||
112 | throw new Exception("Can't read {$filename}"); |
||
113 | } |
||
114 | $stat = stat($filename); |
||
115 | $result = Yaml::parseFile($filename); |
||
116 | if (!$result && $stat['size'] > 0) { |
||
117 | throw new Exception("Can't parse data from {$filename}"); |
||
118 | } |
||
119 | |||
120 | $classes = []; |
||
121 | foreach ($result as $class => $info) { |
||
122 | if (!isset($info['columns'])) { |
||
123 | // @TODO some kind of warning here - or try to read using reflection? |
||
124 | continue; |
||
125 | } |
||
126 | $class = ltrim($class, '\\'); |
||
127 | if (!class_exists($class)) { |
||
128 | throw new Exception("$class - class does not exist"); |
||
129 | } |
||
130 | $classes[$class]['columns'] = []; |
||
131 | foreach ($info['columns'] as $name => $columnDef) { |
||
132 | $label = isset($columnDef['label']) ? $columnDef['label'] : CamelCase::fromCamelCase($name); |
||
133 | $column = ['class' => '\Dtc\GridBundle\Grid\Column\GridColumn', 'arguments' => [$name, $label]]; |
||
134 | $column['arguments'][] = isset($columnDef['formatter']) ? $columnDef['formatter'] : null; |
||
135 | if (isset($columnDef['sortable'])) { |
||
136 | $column['arguments'][] = ['sortable' => $columnDef['sortable'] ? true : false]; |
||
137 | } else { |
||
138 | $column['arguments'][] = []; |
||
139 | } |
||
140 | $column['arguments'][] = isset($columnDef['searchable']) ? ($columnDef['searchable'] ? true : false) : false; |
||
141 | $column['arguments'][] = null; |
||
142 | $classes[$class]['columns'][$name] = $column; |
||
143 | } |
||
144 | |||
145 | if (isset($info['actions'])) { |
||
146 | $field = '\$-action'; |
||
147 | $actionArgs = [$field]; |
||
148 | $actionDefs = []; |
||
149 | /* @var Action $action */ |
||
150 | foreach ($info['actions'] as $action) { |
||
151 | if (!isset($action['label'])) { |
||
152 | throw new Exception("$class - action definition missing 'label' ".print_r($action, true)); |
||
153 | } |
||
154 | if (!isset($action['route'])) { |
||
155 | throw new Exception("$class - action definition missing 'route' ".print_r($action, true)); |
||
156 | } |
||
157 | $actionDef = ['label' => $action['label'], 'route' => $action['route']]; |
||
158 | if (isset($action['onclick'])) { |
||
159 | $actionDef['onclick'] = $action['onclick']; |
||
160 | } |
||
161 | if (isset($action['button_class'])) { |
||
162 | $actionDef['button_class'] = $action['button_class']; |
||
163 | } |
||
164 | |||
165 | switch ($action['type']) { |
||
166 | case 'show': |
||
167 | $actionDef['action'] = 'show'; |
||
168 | break; |
||
169 | case 'delete': |
||
170 | $actionDef['action'] = 'delete'; |
||
171 | break; |
||
172 | default: |
||
173 | |||
174 | } |
||
175 | $actionDefs[] = $actionDef; |
||
176 | } |
||
177 | $actionArgs[] = $actionDefs; |
||
178 | $classes[$class]['columns'][$field] = ['class' => '\Dtc\GridBundle\Grid\Column\ActionGridColumn', 'arguments' => $actionArgs]; |
||
179 | } |
||
180 | if (isset($info['sort'])) { |
||
181 | foreach ($info['sort'] as $key => $value) { |
||
182 | if (!isset($info['columns'][$key])) { |
||
183 | throw new Exception("$class - can't find sort column $key in list of columns."); |
||
184 | } |
||
185 | switch ($value) { |
||
186 | case 'ASC': |
||
187 | break; |
||
188 | case 'DESC': |
||
189 | break; |
||
190 | default: |
||
191 | throw new Exception("$class - sort type should be ASC or DESC instead of $value."); |
||
192 | } |
||
193 | } |
||
194 | $classes[$class]['sort'] = $info['sort']; |
||
195 | } |
||
196 | } |
||
197 | |||
198 | return $classes; |
||
199 | } |
||
201 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths