| Conditions | 26 |
| Paths | 789 |
| Total Lines | 87 |
| Code Lines | 62 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 | if (!isset($action['type'])) { |
||
| 158 | throw new Exception("$class - action definition missing 'type' ".print_r($action, true)); |
||
| 159 | } |
||
| 160 | $actionDef = ['label' => $action['label'], 'route' => $action['route']]; |
||
| 161 | switch ($action['type']) { |
||
| 162 | case 'show': |
||
| 163 | $actionDef['action'] = 'show'; |
||
| 164 | break; |
||
| 165 | case 'delete': |
||
| 166 | $actionDef['action'] = 'delete'; |
||
| 167 | break; |
||
| 168 | default: |
||
| 169 | throw new Exception("$class - action definition unknown 'type' {$action['type']} ".print_r($action, true)); |
||
| 170 | } |
||
| 171 | $actionDefs[] = $actionDef; |
||
| 172 | } |
||
| 173 | $actionArgs[] = $actionDefs; |
||
| 174 | $classes[$class]['columns'][$field] = ['class' => '\Dtc\GridBundle\Grid\Column\ActionGridColumn', 'arguments' => $actionArgs]; |
||
| 175 | } |
||
| 176 | if (isset($info['sort'])) { |
||
| 177 | foreach ($info['sort'] as $key => $value) { |
||
| 178 | if (!isset($info['columns'][$key])) { |
||
| 179 | throw new Exception("$class - can't find sort column $key in list of columns."); |
||
| 180 | } |
||
| 181 | switch ($value) { |
||
| 182 | case 'ASC': |
||
| 183 | break; |
||
| 184 | case 'DESC': |
||
| 185 | break; |
||
| 186 | default: |
||
| 187 | throw new Exception("$class - sort type should be ASC or DESC instead of $value."); |
||
| 188 | } |
||
| 189 | } |
||
| 190 | $classes[$class]['sort'] = $info['sort']; |
||
| 191 | } |
||
| 192 | } |
||
| 193 | |||
| 194 | return $classes; |
||
| 195 | } |
||
| 197 |
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