Conditions | 10 |
Paths | 16 |
Total Lines | 24 |
Code Lines | 14 |
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 |
||
41 | public function handleSalsifyRelationType($class, $data, $dataField, $config, $dbField) |
||
42 | { |
||
43 | if (!array_key_exists('salsify:relations', $data)) { |
||
44 | return []; |
||
45 | } |
||
46 | |||
47 | $related = []; |
||
48 | $fieldData = $data['salsify:relations']; |
||
49 | foreach ($this->owner->yieldSingle($fieldData) as $relation) { |
||
50 | if (array_key_exists('relation_type', $relation) && $relation['relation_type'] == $dataField) { |
||
51 | $related[] = DataObject::get($class)->find('SalsifyID', $relation['salsify:target_product_id']); |
||
52 | } |
||
53 | } |
||
54 | |||
55 | $related = array_filter($related); |
||
56 | |||
57 | if (array_key_exists('single', $config) && $config['single'] == true) { |
||
58 | if (count($related)) { |
||
59 | $object = $related[0]; |
||
60 | return preg_match('/ID$/', $dbField) ? $object->ID : $object; |
||
61 | } |
||
62 | return preg_match('/ID$/', $dbField) ? 0 : null; |
||
63 | } |
||
64 | return $related; |
||
65 | } |
||
67 |