Conditions | 2 |
Paths | 2 |
Total Lines | 59 |
Code Lines | 49 |
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 declare(strict_types=1); |
||
87 | public function fetch(array $ids): array |
||
88 | { |
||
89 | $data = $this->connection->fetchAllAssociative( |
||
90 | ' |
||
91 | SELECT LOWER(HEX(order.id)) as id, |
||
92 | GROUP_CONCAT(DISTINCT tag.name) as tags, |
||
93 | GROUP_CONCAT(DISTINCT country_translation.name) as country, |
||
94 | GROUP_CONCAT(DISTINCT order_address.city) as city, |
||
95 | GROUP_CONCAT(DISTINCT order_address.street) as street, |
||
96 | GROUP_CONCAT(DISTINCT order_address.zipcode) as zipcode, |
||
97 | GROUP_CONCAT(DISTINCT order_address.phone_number) as phone_number, |
||
98 | GROUP_CONCAT(DISTINCT order_address.additional_address_line1) as additional_address_line1, |
||
99 | GROUP_CONCAT(DISTINCT order_address.additional_address_line2) as additional_address_line2, |
||
100 | GROUP_CONCAT(DISTINCT JSON_UNQUOTE(JSON_EXTRACT(document.config, "$.documentNumber"))) as documentNumber, |
||
101 | order_customer.first_name, |
||
102 | order_customer.last_name, |
||
103 | order_customer.email, |
||
104 | order_customer.company, |
||
105 | order_customer.customer_number, |
||
106 | `order`.order_number, |
||
107 | `order`.amount_total, |
||
108 | order_delivery.tracking_codes |
||
109 | FROM `order` |
||
110 | LEFT JOIN order_customer |
||
111 | ON `order`.id = order_customer.order_id |
||
112 | LEFT JOIN order_address |
||
113 | ON `order`.id = order_address.order_id |
||
114 | LEFT JOIN country |
||
115 | ON order_address.country_id = country.id |
||
116 | LEFT JOIN country_translation |
||
117 | ON country.id = country_translation.country_id |
||
118 | LEFT JOIN order_tag |
||
119 | ON `order`.id = order_tag.order_id |
||
120 | LEFT JOIN tag |
||
121 | ON order_tag.tag_id = tag.id |
||
122 | LEFT JOIN order_delivery |
||
123 | ON `order`.id = order_delivery.order_id |
||
124 | LEFT JOIN document |
||
125 | ON `order`.id = document.order_id |
||
126 | WHERE order.id IN (:ids) AND `order`.version_id = :versionId |
||
127 | GROUP BY order.id |
||
128 | ', |
||
129 | [ |
||
130 | 'ids' => Uuid::fromHexToBytesList($ids), |
||
131 | 'versionId' => Uuid::fromHexToBytes(Defaults::LIVE_VERSION), |
||
132 | ], |
||
133 | [ |
||
134 | 'ids' => Connection::PARAM_STR_ARRAY, |
||
135 | ] |
||
136 | ); |
||
137 | |||
138 | $mapped = []; |
||
139 | foreach ($data as $row) { |
||
140 | $id = $row['id']; |
||
141 | $text = \implode(' ', array_filter(array_unique(array_values($row)))); |
||
142 | $mapped[$id] = ['id' => $id, 'text' => \strtolower($text)]; |
||
143 | } |
||
144 | |||
145 | return $mapped; |
||
146 | } |
||
148 |