Conditions | 12 |
Paths | 324 |
Total Lines | 55 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 | |||
53 | $grid->addFilter($filter); |
||
54 | } |
||
55 | |||
56 | foreach ($configuration['actions'] as $groupName => $actions) { |
||
57 | $actionGroup = ActionGroup::named($groupName); |
||
58 | |||
59 | foreach ($actions as $name => $actionConfiguration) { |
||
60 | $action = Action::fromNameAndType($name, $actionConfiguration['type']); |
||
61 | |||
62 | if (array_key_exists('label', $actionConfiguration)) { |
||
63 | $action->setLabel($actionConfiguration['label']); |
||
64 | } |
||
65 | if (array_key_exists('options', $actionConfiguration)) { |
||
66 | $action->setOptions($actionConfiguration['options']); |
||
67 | } |
||
68 | |||
69 | $actionGroup->addAction($action); |
||
70 | } |
||
71 | |||
72 | $grid->addActionGroup($actionGroup); |
||
73 | } |
||
74 | |||
75 | return $grid; |
||
76 | } |
||
77 | } |
||
78 |