Conditions | 10 |
Paths | 11 |
Total Lines | 38 |
Code Lines | 25 |
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 |
||
77 | private function parseProperties(array $properties): array |
||
78 | { |
||
79 | $options = []; |
||
80 | |||
81 | $properties = array_filter($properties, function ($var) { |
||
82 | return !is_null($var); |
||
83 | }); |
||
84 | |||
85 | foreach ($properties as $property => $value) { |
||
86 | switch ($property) { |
||
87 | case 'Label': |
||
88 | $options['label'] = $value; |
||
89 | break; |
||
90 | case 'Default': |
||
91 | $options['data'] = $value; |
||
92 | break; |
||
93 | case 'Constraints': |
||
94 | $attributes = \json_decode($value, true); |
||
95 | |||
96 | if ((\json_last_error() !== JSON_ERROR_NONE)) { |
||
97 | $attributes = [$value]; |
||
98 | } |
||
99 | |||
100 | foreach ($attributes as $attribute => $_value) { |
||
101 | if ($attribute == 'required' || $_value == 'required') { |
||
102 | $options['required'] = true; |
||
103 | } else { |
||
104 | $options['attr'][$attribute] = $_value; |
||
105 | } |
||
106 | } |
||
107 | break; |
||
108 | case 'InputHelp': |
||
109 | $options['help'] = $value; |
||
110 | break; |
||
111 | } |
||
112 | } |
||
113 | |||
114 | return $options; |
||
115 | } |
||
142 |