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 ) |
||
| 79 | |||
| 80 | |||
| 81 | /** |
||
| 82 | * Creates a new customer item object pre-filled with the given values but not yet stored |
||
| 83 | * |
||
| 84 | * @return \Aimeos\MShop\Customer\Item\Iface Customer item |
||
| 85 | */ |
||
| 86 | public function createItem( array $values = [] ) |
||
| 91 | |||
| 92 | |||
| 93 | /** |
||
| 94 | * Deletes a customer item that belongs to the current authenticated user |
||
| 95 | * |
||
| 96 | * @param string $id Unique customer ID |
||
| 97 | * @since 2017.04 |
||
| 98 | */ |
||
| 99 | public function deleteItem( $id ) |
||
| 106 | |||
| 107 | |||
| 108 | /** |
||
| 109 | * Updates the customer item identified by its ID |
||
| 110 | * |
||
| 111 | * @param string $id Unique customer ID |
||
| 112 | * @param array $values Values added to the customer item like "customer.birthday" or "customer.city" |
||
| 113 | * @return \Aimeos\MShop\Customer\Item\Iface Customer item |
||
| 114 | * @since 2017.04 |
||
| 115 | */ |
||
| 116 | public function editItem( $id, array $values ) |
||
| 126 | |||
| 127 | |||
| 128 | /** |
||
| 129 | * Returns the customer item for the given customer ID |
||
| 130 | * |
||
| 131 | * @param string|null $id Unique customer ID or null for current customer item |
||
| 132 | * @param string[] $domains Domain names of items that are associated with the customers and that should be fetched too |
||
| 133 | * @return \Aimeos\MShop\Customer\Item\Iface Customer item including the referenced domains items |
||
| 134 | * @since 2017.04 |
||
| 135 | */ |
||
| 136 | public function getItem( $id = null, array $domains = [] ) |
||
| 148 | |||
| 149 | |||
| 150 | /** |
||
| 151 | * Returns the customer item for the given customer code (usually e-mail address) |
||
| 152 | * |
||
| 153 | * This method doesn't check if the customer item belongs to the logged in user! |
||
| 154 | * |
||
| 155 | * @param string $code Unique customer code |
||
| 156 | * @param string[] $domains Domain names of items that are associated with the customers and that should be fetched too |
||
| 157 | * @return \Aimeos\MShop\Customer\Item\Iface Customer item including the referenced domains items |
||
| 158 | * @since 2017.04 |
||
| 159 | */ |
||
| 160 | public function findItem( $code, array $domains = [] ) |
||
| 164 | |||
| 165 | |||
| 166 | /** |
||
| 167 | * Stores a modified customer item |
||
| 168 | * |
||
| 169 | * @param \Aimeos\MShop\Customer\Item\Iface $item Customer item |
||
| 170 | * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item including the generated ID |
||
| 171 | */ |
||
| 172 | public function saveItem( \Aimeos\MShop\Customer\Item\Iface $item ) |
||
| 176 | |||
| 177 | |||
| 178 | /** |
||
| 179 | * Creates and returns a new item object |
||
| 180 | * |
||
| 181 | * @param array $values Values added to the newly created customer item like "customer.birthday" |
||
| 182 | * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item |
||
| 183 | * @since 2017.04 |
||
| 184 | */ |
||
| 185 | public function addAddressItem( array $values ) |
||
| 193 | |||
| 194 | |||
| 195 | /** |
||
| 196 | * Creates a new customer address item object pre-filled with the given values but not yet stored |
||
| 197 | * |
||
| 198 | * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item |
||
| 199 | */ |
||
| 200 | public function createAddressItem( array $values = [] ) |
||
| 207 | |||
| 208 | |||
| 209 | /** |
||
| 210 | * Deletes a customer item that belongs to the current authenticated user |
||
| 211 | * |
||
| 212 | * @param string $id Unique customer address ID |
||
| 213 | * @since 2017.04 |
||
| 214 | */ |
||
| 215 | public function deleteAddressItem( $id ) |
||
| 223 | |||
| 224 | |||
| 225 | /** |
||
| 226 | * Saves a modified customer item object |
||
| 227 | * |
||
| 228 | * @param string $id Unique customer address ID |
||
| 229 | * @param array $values Values added to the customer item like "customer.address.city" |
||
| 230 | * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item |
||
| 231 | * @since 2017.04 |
||
| 232 | */ |
||
| 233 | public function editAddressItem( $id, array $values ) |
||
| 243 | |||
| 244 | |||
| 245 | /** |
||
| 246 | * Returns the customer item for the given customer ID |
||
| 247 | * |
||
| 248 | * @param string $id Unique customer address ID |
||
| 249 | * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item |
||
| 250 | * @since 2017.04 |
||
| 251 | */ |
||
| 252 | public function getAddressItem( $id ) |
||
| 261 | |||
| 262 | |||
| 263 | /** |
||
| 264 | * Stores a modified customer address item |
||
| 265 | * |
||
| 266 | * @param \Aimeos\MShop\Customer\Item\Address\Iface $item Customer address item |
||
| 267 | * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item including the generated ID |
||
| 268 | */ |
||
| 269 | public function saveAddressItem( \Aimeos\MShop\Customer\Item\Address\Iface $item ) |
||
| 273 | |||
| 274 | |||
| 275 | /** |
||
| 276 | * Creates and returns a new list item object |
||
| 277 | * |
||
| 278 | * @param array $values Values added to the newly created customer item like "customer.lists.refid" |
||
| 279 | * @return \Aimeos\MShop\Common\Item\Lists\Iface Customer lists item |
||
| 280 | * @since 2017.06 |
||
| 281 | */ |
||
| 282 | public function addListItem( array $values ) |
||
| 305 | |||
| 306 | |||
| 307 | /** |
||
| 308 | * Returns a new customer lists filter criteria object |
||
| 309 | * |
||
| 310 | * @return \Aimeos\MW\Criteria\Iface New filter object |
||
| 311 | * @since 2017.06 |
||
| 312 | */ |
||
| 313 | public function createListsFilter() |
||
| 323 | |||
| 324 | |||
| 325 | /** |
||
| 326 | * Deletes a customer item that belongs to the current authenticated user |
||
| 327 | * |
||
| 328 | * @param string $id Unique customer address ID |
||
| 329 | * @since 2017.06 |
||
| 330 | */ |
||
| 331 | public function deleteListItem( $id ) |
||
| 339 | |||
| 340 | |||
| 341 | /** |
||
| 342 | * Saves a modified customer lists item object |
||
| 343 | * |
||
| 344 | * @param string $id Unique customer lists ID |
||
| 345 | * @param array $values Values added to the customer lists item like "customer.lists.refid" |
||
| 346 | * @return \Aimeos\MShop\Common\Item\Lists\Iface Customer lists item |
||
| 347 | * @since 2017.06 |
||
| 348 | */ |
||
| 349 | public function editListItem( $id, array $values ) |
||
| 375 | |||
| 376 | |||
| 377 | /** |
||
| 378 | * Returns the customer item for the given customer ID |
||
| 379 | * |
||
| 380 | * @param string $id Unique customer address ID |
||
| 381 | * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item |
||
| 382 | * @since 2017.06 |
||
| 383 | */ |
||
| 384 | public function getListItem( $id ) |
||
| 393 | |||
| 394 | |||
| 395 | /** |
||
| 396 | * Returns the customer lists items filtered by the given criteria |
||
| 397 | * |
||
| 398 | * @param \Aimeos\MW\Criteria\Iface $filter Criteria object which contains the filter conditions |
||
| 399 | * @param integer &$total Parameter where the total number of found attributes will be stored in |
||
| 400 | * @return \Aimeos\MShop\Common\Item\Lists\Iface[] Customer list items |
||
| 401 | * @since 2017.06 |
||
| 402 | */ |
||
| 403 | public function searchListItems( \Aimeos\MW\Criteria\Iface $filter, &$total = null ) |
||
| 409 | |||
| 410 | |||
| 411 | /** |
||
| 412 | * Adds the default values for customer items if not yet available |
||
| 413 | * |
||
| 414 | * @param string[] $values Associative list of customer keys (e.g. "customer.label") and their values |
||
| 415 | * @return string[] Associative list of customer key/value pairs with default values set |
||
| 416 | */ |
||
| 417 | protected function addItemDefaults( array $values ) |
||
| 448 | |||
| 449 | |||
| 450 | /** |
||
| 451 | * Checks if the current user is allowed to create more customer accounts |
||
| 452 | * |
||
| 453 | * @param string[] $values Associative list of customer keys (e.g. "customer.label") and their values |
||
| 454 | * @throws \Aimeos\Controller\Frontend\Customer\Exception If access isn't allowed |
||
| 455 | */ |
||
| 456 | protected function checkLimit( array $values ) |
||
| 513 | |||
| 514 | |||
| 515 | /** |
||
| 516 | * Checks if the current user is allowed to retrieve the customer data for the given ID |
||
| 517 | * |
||
| 518 | * @param string $id Unique customer ID |
||
| 519 | * @throws \Aimeos\Controller\Frontend\Customer\Exception If access isn't allowed |
||
| 520 | */ |
||
| 521 | protected function checkUser( $id ) |
||
| 529 | } |
||
| 530 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.