| Conditions | 13 |
| Paths | 540 |
| Total Lines | 58 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | 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 |
||
| 22 | public function convert($code, array $configuration) |
||
| 23 | { |
||
| 24 | $grid = Grid::fromCodeAndDriverConfiguration($code, $configuration['driver']['name'], $configuration['driver']['options']); |
||
| 25 | |||
| 26 | if (array_key_exists('sorting', $configuration)) { |
||
| 27 | $grid->setSorting($configuration['sorting']); |
||
| 28 | } |
||
| 29 | |||
| 30 | foreach ($configuration['fields'] as $name => $fieldConfiguration) { |
||
| 31 | $field = Field::fromNameAndType($name, $fieldConfiguration['type']); |
||
| 32 | |||
| 33 | if (array_key_exists('path', $fieldConfiguration)) { |
||
| 34 | $field->setPath($fieldConfiguration['path']); |
||
| 35 | } |
||
| 36 | if (array_key_exists('label', $fieldConfiguration)) { |
||
| 37 | $field->setLabel($fieldConfiguration['label']); |
||
| 38 | } |
||
| 39 | if (array_key_exists('options', $fieldConfiguration)) { |
||
| 40 | $field->setOptions($fieldConfiguration['options']); |
||
| 41 | } |
||
| 42 | |||
| 43 | $grid->addField($field); |
||
| 44 | } |
||
| 45 | |||
| 46 | foreach ($configuration['filters'] as $name => $filterConfiguration) { |
||
| 47 | $filter = Filter::fromNameAndType($name, $filterConfiguration['type']); |
||
| 48 | |||
| 49 | if (array_key_exists('label', $filterConfiguration)) { |
||
| 50 | $filter->setLabel($filterConfiguration['label']); |
||
| 51 | } |
||
| 52 | if (array_key_exists('options', $filterConfiguration)) { |
||
| 53 | $filter->setOptions($filterConfiguration['options']); |
||
| 54 | } |
||
| 55 | |||
| 56 | $grid->addFilter($filter); |
||
| 57 | } |
||
| 58 | |||
| 59 | foreach ($configuration['actions'] as $groupName => $actions) { |
||
| 60 | $actionGroup = ActionGroup::named($groupName); |
||
| 61 | |||
| 62 | foreach ($actions as $name => $actionConfiguration) { |
||
| 63 | $action = Action::fromNameAndType($name, $actionConfiguration['type']); |
||
| 64 | |||
| 65 | if (array_key_exists('label', $actionConfiguration)) { |
||
| 66 | $action->setLabel($actionConfiguration['label']); |
||
| 67 | } |
||
| 68 | if (array_key_exists('options', $actionConfiguration)) { |
||
| 69 | $action->setOptions($actionConfiguration['options']); |
||
| 70 | } |
||
| 71 | |||
| 72 | $actionGroup->addAction($action); |
||
| 73 | } |
||
| 74 | |||
| 75 | $grid->addActionGroup($actionGroup); |
||
| 76 | } |
||
| 77 | |||
| 78 | return $grid; |
||
| 79 | } |
||
| 80 | } |
||
| 81 |