Complex classes like Base 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 Base, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 20 | abstract class Base |
||
| 21 | { |
||
| 22 | private $view; |
||
| 23 | private $context; |
||
| 24 | private $templatePaths; |
||
| 25 | private $path; |
||
| 26 | |||
| 27 | |||
| 28 | /** |
||
| 29 | * Initializes the client |
||
| 30 | * |
||
| 31 | * @param \Aimeos\MShop\Context\Item\Iface $context MShop context object |
||
| 32 | * @param \Aimeos\MW\View\Iface $view View object |
||
| 33 | * @param array $templatePaths List of file system paths where the templates are stored |
||
| 34 | * @param string $path Name of the client separated by slashes, e.g "product/property" |
||
| 35 | */ |
||
| 36 | public function __construct( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MW\View\Iface $view, array $templatePaths, $path ) |
||
| 43 | |||
| 44 | |||
| 45 | /** |
||
| 46 | * Catch unknown methods |
||
| 47 | * |
||
| 48 | * @param string $name Name of the method |
||
| 49 | * @param array $param List of method parameter |
||
| 50 | * @throws \Aimeos\Admin\JsonAdm\Exception If method call failed |
||
| 51 | */ |
||
| 52 | public function __call( $name, array $param ) |
||
| 56 | |||
| 57 | |||
| 58 | /** |
||
| 59 | * Returns the items with parent/child relationships |
||
| 60 | * |
||
| 61 | * @param array $items List of items implementing \Aimeos\MShop\Common\Item\Iface |
||
| 62 | * @param array $include List of resource types that should be fetched |
||
| 63 | * @return array List of items implementing \Aimeos\MShop\Common\Item\Iface |
||
| 64 | */ |
||
| 65 | protected function getChildItems( array $items, array $include ) |
||
| 69 | |||
| 70 | |||
| 71 | /** |
||
| 72 | * Returns the context item object |
||
| 73 | * |
||
| 74 | * @return \Aimeos\MShop\Context\Item\Iface Context object |
||
| 75 | */ |
||
| 76 | protected function getContext() |
||
| 80 | |||
| 81 | |||
| 82 | /** |
||
| 83 | * Returns the list of domains that are available as resources |
||
| 84 | * |
||
| 85 | * @param \Aimeos\MW\View\Iface $view View object with "resource" parameter |
||
| 86 | * @return array List of domain names |
||
| 87 | */ |
||
| 88 | protected function getDomains( \Aimeos\MW\View\Iface $view ) |
||
| 118 | |||
| 119 | |||
| 120 | /** |
||
| 121 | * Returns the IDs sent in the request body |
||
| 122 | * |
||
| 123 | * @param \stdClass $request Decoded request body |
||
| 124 | * @return array List of item IDs |
||
| 125 | */ |
||
| 126 | protected function getIds( $request ) |
||
| 142 | |||
| 143 | |||
| 144 | /** |
||
| 145 | * Returns the list items for association relationships |
||
| 146 | * |
||
| 147 | * @param array $items List of items implementing \Aimeos\MShop\Common\Item\Iface |
||
| 148 | * @param array $include List of resource types that should be fetched |
||
| 149 | * @return array List of items implementing \Aimeos\MShop\Common\Item\Lists\Iface |
||
| 150 | */ |
||
| 151 | protected function getListItems( array $items, array $include ) |
||
| 155 | |||
| 156 | |||
| 157 | /** |
||
| 158 | * Returns the path to the client |
||
| 159 | * |
||
| 160 | * @return string Client path, e.g. "product/property" |
||
| 161 | */ |
||
| 162 | protected function getPath() |
||
| 166 | |||
| 167 | |||
| 168 | /** |
||
| 169 | * Returns the items associated via a lists table |
||
| 170 | * |
||
| 171 | * @param array $listItems List of items implementing \Aimeos\MShop\Common\Item\Lists\Iface |
||
| 172 | * @return array List of items implementing \Aimeos\MShop\Common\Item\Iface |
||
| 173 | */ |
||
| 174 | protected function getRefItems( array $listItems ) |
||
| 195 | |||
| 196 | |||
| 197 | /** |
||
| 198 | * Returns the list of additional resources |
||
| 199 | * |
||
| 200 | * @param \Aimeos\MW\View\Iface $view View object with "resource" parameter |
||
| 201 | * @return array List of domain names |
||
| 202 | */ |
||
| 203 | protected function getResources( \Aimeos\MW\View\Iface $view ) |
||
| 223 | |||
| 224 | |||
| 225 | /** |
||
| 226 | * Returns the paths to the template files |
||
| 227 | * |
||
| 228 | * @return array List of file system paths |
||
| 229 | */ |
||
| 230 | protected function getTemplatePaths() |
||
| 234 | |||
| 235 | |||
| 236 | /** |
||
| 237 | * Returns the view object |
||
| 238 | * |
||
| 239 | * @return \Aimeos\MW\View\Iface View object |
||
| 240 | */ |
||
| 241 | protected function getView() |
||
| 245 | |||
| 246 | |||
| 247 | /** |
||
| 248 | * Initializes the criteria object based on the given parameter |
||
| 249 | * |
||
| 250 | * @param \Aimeos\MW\Criteria\Iface $criteria Criteria object |
||
| 251 | * @param array $params List of criteria data with condition, sorting and paging |
||
| 252 | * @return \Aimeos\MW\Criteria\Iface Initialized criteria object |
||
| 253 | */ |
||
| 254 | protected function initCriteria( \Aimeos\MW\Criteria\Iface $criteria, array $params ) |
||
| 262 | |||
| 263 | |||
| 264 | /** |
||
| 265 | * Initializes the criteria object with conditions based on the given parameter |
||
| 266 | * |
||
| 267 | * @param \Aimeos\MW\Criteria\Iface $criteria Criteria object |
||
| 268 | * @param array $params List of criteria data with condition, sorting and paging |
||
| 269 | */ |
||
| 270 | protected function initCriteriaConditions( \Aimeos\MW\Criteria\Iface $criteria, array $params ) |
||
| 282 | |||
| 283 | |||
| 284 | /** |
||
| 285 | * Initializes the criteria object with the slice based on the given parameter. |
||
| 286 | * |
||
| 287 | * @param \Aimeos\MW\Criteria\Iface $criteria Criteria object |
||
| 288 | * @param array $params List of criteria data with condition, sorting and paging |
||
| 289 | */ |
||
| 290 | protected function initCriteriaSlice( \Aimeos\MW\Criteria\Iface $criteria, array $params ) |
||
| 297 | |||
| 298 | |||
| 299 | /** |
||
| 300 | * Initializes the criteria object with sortations based on the given parameter |
||
| 301 | * |
||
| 302 | * @param \Aimeos\MW\Criteria\Iface $criteria Criteria object |
||
| 303 | * @param array $params List of criteria data with condition, sorting and paging |
||
| 304 | */ |
||
| 305 | protected function initCriteriaSortations( \Aimeos\MW\Criteria\Iface $criteria, array $params ) |
||
| 324 | |||
| 325 | |||
| 326 | /** |
||
| 327 | * Creates of updates several items at once |
||
| 328 | * |
||
| 329 | * @param \Aimeos\MShop\Common\Manager\Iface $manager Manager responsible for the items |
||
| 330 | * @param \stdClass $request Object with request body data |
||
| 331 | * @return array List of items |
||
| 332 | */ |
||
| 333 | protected function saveData( \Aimeos\MShop\Common\Manager\Iface $manager, \stdClass $request ) |
||
| 346 | |||
| 347 | |||
| 348 | /** |
||
| 349 | * Saves and returns the new or updated item |
||
| 350 | * |
||
| 351 | * @param \Aimeos\MShop\Common\Manager\Iface $manager Manager responsible for the items |
||
| 352 | * @param \stdClass $entry Object including "id" and "attributes" elements |
||
| 353 | * @return \Aimeos\MShop\Common\Item\Iface New or updated item |
||
| 354 | */ |
||
| 355 | protected function saveEntry( \Aimeos\MShop\Common\Manager\Iface $manager, \stdClass $entry ) |
||
| 372 | |||
| 373 | |||
| 374 | /** |
||
| 375 | * Saves the item references associated via the list |
||
| 376 | * |
||
| 377 | * @param \Aimeos\MShop\Common\Manager\Iface $manager Manager responsible for the items |
||
| 378 | * @param \Aimeos\MShop\Common\Item\Iface $item Domain item with an unique ID set |
||
| 379 | * @param \stdClass $relationships Object including the <domain>/data/attributes structure |
||
| 380 | */ |
||
| 381 | protected function saveRelationships( \Aimeos\MShop\Common\Manager\Iface $manager, |
||
| 407 | |||
| 408 | |||
| 409 | /** |
||
| 410 | * Adds the data from the given object to the item |
||
| 411 | * |
||
| 412 | * @param \Aimeos\MShop\Common\Manager\Iface $manager Manager object |
||
| 413 | * @param \Aimeos\MShop\Common\Item\Iface $item Item object to add the data to |
||
| 414 | * @param \stdClass $data Object with "attributes" property |
||
| 415 | * @param string $domain Domain of the type item |
||
| 416 | * @return \Aimeos\MShop\Common\Item\Iface Item including the data |
||
| 417 | */ |
||
| 418 | protected function addItemData(\Aimeos\MShop\Common\Manager\Iface $manager, |
||
| 437 | } |
||
| 438 |
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.