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