Complex classes like Standard often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Standard, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
20 | class Standard |
||
21 | extends \Aimeos\Controller\Frontend\Base |
||
22 | implements Iface, \Aimeos\Controller\Frontend\Common\Iface |
||
23 | { |
||
24 | /** |
||
25 | * Adds and returns a new customer item object |
||
26 | * |
||
27 | * @param array $values Values added to the newly created customer item like "customer.birthday" |
||
28 | * @return \Aimeos\MShop\Customer\Item\Iface Customer item |
||
29 | * @since 2017.04 |
||
30 | */ |
||
31 | public function addItem( array $values ) |
||
75 | |||
76 | |||
77 | /** |
||
78 | * Creates a new customer item object pre-filled with the given values but not yet stored |
||
79 | * |
||
80 | * @return \Aimeos\MShop\Customer\Item\Iface Customer item |
||
81 | */ |
||
82 | public function createItem( array $values = [] ) |
||
93 | |||
94 | |||
95 | /** |
||
96 | * Deletes a customer item that belongs to the current authenticated user |
||
97 | * |
||
98 | * @param string $id Unique customer ID |
||
99 | * @since 2017.04 |
||
100 | */ |
||
101 | public function deleteItem( $id ) |
||
108 | |||
109 | |||
110 | /** |
||
111 | * Updates the customer item identified by its ID |
||
112 | * |
||
113 | * @param string $id Unique customer ID |
||
114 | * @param array $values Values added to the customer item like "customer.birthday" or "customer.city" |
||
115 | * @return \Aimeos\MShop\Customer\Item\Iface Customer item |
||
116 | * @since 2017.04 |
||
117 | */ |
||
118 | public function editItem( $id, array $values ) |
||
130 | |||
131 | |||
132 | /** |
||
133 | * Returns the customer item for the given customer ID |
||
134 | * |
||
135 | * @param string|null $id Unique customer ID or null for current customer item |
||
136 | * @param string[] $domains Domain names of items that are associated with the customers and that should be fetched too |
||
137 | * @return \Aimeos\MShop\Customer\Item\Iface Customer item including the referenced domains items |
||
138 | * @since 2017.04 |
||
139 | */ |
||
140 | public function getItem( $id = null, array $domains = [] ) |
||
152 | |||
153 | |||
154 | /** |
||
155 | * Returns the customer item for the given customer code (usually e-mail address) |
||
156 | * |
||
157 | * This method doesn't check if the customer item belongs to the logged in user! |
||
158 | * |
||
159 | * @param string $code Unique customer code |
||
160 | * @param string[] $domains Domain names of items that are associated with the customers and that should be fetched too |
||
161 | * @return \Aimeos\MShop\Customer\Item\Iface Customer item including the referenced domains items |
||
162 | * @since 2017.04 |
||
163 | */ |
||
164 | public function findItem( $code, array $domains = [] ) |
||
168 | |||
169 | |||
170 | /** |
||
171 | * Stores a modified customer item |
||
172 | * |
||
173 | * @param \Aimeos\MShop\Customer\Item\Iface $item Customer item |
||
174 | * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item including the generated ID |
||
175 | */ |
||
176 | public function saveItem( \Aimeos\MShop\Customer\Item\Iface $item ) |
||
180 | |||
181 | |||
182 | /** |
||
183 | * Creates and returns a new item object |
||
184 | * |
||
185 | * @param array $values Values added to the newly created customer item like "customer.birthday" |
||
186 | * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item |
||
187 | * @since 2017.04 |
||
188 | */ |
||
189 | public function addAddressItem( array $values ) |
||
201 | |||
202 | |||
203 | /** |
||
204 | * Creates a new customer address item object pre-filled with the given values but not yet stored |
||
205 | * |
||
206 | * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item |
||
207 | */ |
||
208 | public function createAddressItem( array $values = [] ) |
||
221 | |||
222 | |||
223 | /** |
||
224 | * Deletes a customer item that belongs to the current authenticated user |
||
225 | * |
||
226 | * @param string $id Unique customer address ID |
||
227 | * @since 2017.04 |
||
228 | */ |
||
229 | public function deleteAddressItem( $id ) |
||
237 | |||
238 | |||
239 | /** |
||
240 | * Saves a modified customer item object |
||
241 | * |
||
242 | * @param string $id Unique customer address ID |
||
243 | * @param array $values Values added to the customer item like "customer.address.city" |
||
244 | * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item |
||
245 | * @since 2017.04 |
||
246 | */ |
||
247 | public function editAddressItem( $id, array $values ) |
||
259 | |||
260 | |||
261 | /** |
||
262 | * Returns the customer item for the given customer ID |
||
263 | * |
||
264 | * @param string $id Unique customer address ID |
||
265 | * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item |
||
266 | * @since 2017.04 |
||
267 | */ |
||
268 | public function getAddressItem( $id ) |
||
277 | |||
278 | |||
279 | /** |
||
280 | * Stores a modified customer address item |
||
281 | * |
||
282 | * @param \Aimeos\MShop\Customer\Item\Address\Iface $item Customer address item |
||
283 | * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item including the generated ID |
||
284 | */ |
||
285 | public function saveAddressItem( \Aimeos\MShop\Customer\Item\Address\Iface $item ) |
||
289 | |||
290 | |||
291 | /** |
||
292 | * Creates and returns a new list item object |
||
293 | * |
||
294 | * @param array $values Values added to the newly created customer item like "customer.lists.refid" |
||
295 | * @return \Aimeos\MShop\Common\Item\Lists\Iface Customer lists item |
||
296 | * @since 2017.06 |
||
297 | */ |
||
298 | public function addListItem( array $values ) |
||
325 | |||
326 | |||
327 | /** |
||
328 | * Returns a new customer lists filter criteria object |
||
329 | * |
||
330 | * @return \Aimeos\MW\Criteria\Iface New filter object |
||
331 | * @since 2017.06 |
||
332 | */ |
||
333 | public function createListsFilter() |
||
343 | |||
344 | |||
345 | /** |
||
346 | * Deletes a customer item that belongs to the current authenticated user |
||
347 | * |
||
348 | * @param string $id Unique customer address ID |
||
349 | * @since 2017.06 |
||
350 | */ |
||
351 | public function deleteListItem( $id ) |
||
359 | |||
360 | |||
361 | /** |
||
362 | * Saves a modified customer lists item object |
||
363 | * |
||
364 | * @param string $id Unique customer lists ID |
||
365 | * @param array $values Values added to the customer lists item like "customer.lists.refid" |
||
366 | * @return \Aimeos\MShop\Common\Item\Lists\Iface Customer lists item |
||
367 | * @since 2017.06 |
||
368 | */ |
||
369 | public function editListItem( $id, array $values ) |
||
397 | |||
398 | |||
399 | /** |
||
400 | * Returns the customer item for the given customer ID |
||
401 | * |
||
402 | * @param string $id Unique customer address ID |
||
403 | * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item |
||
404 | * @since 2017.06 |
||
405 | */ |
||
406 | public function getListItem( $id ) |
||
415 | |||
416 | |||
417 | /** |
||
418 | * Returns the customer lists items filtered by the given criteria |
||
419 | * |
||
420 | * @param \Aimeos\MW\Criteria\Iface $filter Criteria object which contains the filter conditions |
||
421 | * @param integer &$total Parameter where the total number of found attributes will be stored in |
||
422 | * @return \Aimeos\MShop\Common\Item\Lists\Iface[] Customer list items |
||
423 | * @since 2017.06 |
||
424 | */ |
||
425 | public function searchListItems( \Aimeos\MW\Criteria\Iface $filter, &$total = null ) |
||
431 | |||
432 | |||
433 | /** |
||
434 | * Adds the default values for customer items if not yet available |
||
435 | * |
||
436 | * @param string[] $values Associative list of customer keys (e.g. "customer.label") and their values |
||
437 | * @return string[] Associative list of customer key/value pairs with default values set |
||
438 | */ |
||
439 | protected function addItemDefaults( array $values ) |
||
474 | |||
475 | |||
476 | /** |
||
477 | * Checks if the current user is allowed to create more customer accounts |
||
478 | * |
||
479 | * @param string[] $values Associative list of customer keys (e.g. "customer.label") and their values |
||
480 | * @throws \Aimeos\Controller\Frontend\Customer\Exception If access isn't allowed |
||
481 | */ |
||
482 | protected function checkLimit( array $values ) |
||
539 | |||
540 | |||
541 | /** |
||
542 | * Checks if the current user is allowed to retrieve the customer data for the given ID |
||
543 | * |
||
544 | * @param string $id Unique customer ID |
||
545 | * @throws \Aimeos\Controller\Frontend\Customer\Exception If access isn't allowed |
||
546 | */ |
||
547 | protected function checkUser( $id ) |
||
555 | } |
||
556 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.