Complex classes like LocalizationDomainTrait 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 LocalizationDomainTrait, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 24 | trait LocalizationDomainTrait { |
||
| 25 | |||
| 26 | /** |
||
| 27 | */ |
||
| 28 | protected $pool; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Adds LanguageVariant to Localization |
||
| 32 | * |
||
| 33 | * @param mixed $id |
||
| 34 | * @param mixed $data |
||
| 35 | * @return PayloadInterface |
||
| 36 | */ |
||
| 37 | public function addLanguageVariant($id, $data) { |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Creates a new Localization with the provided data |
||
| 70 | * |
||
| 71 | * @param mixed $data |
||
| 72 | * @return PayloadInterface |
||
| 73 | */ |
||
| 74 | public function create($data) { |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Deletes a Localization with the given id |
||
| 92 | * |
||
| 93 | * @param mixed $id |
||
| 94 | * @return PayloadInterface |
||
| 95 | */ |
||
| 96 | public function delete($id) { |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Returns a paginated result |
||
| 116 | * |
||
| 117 | * @param Parameters $params |
||
| 118 | * @return PayloadInterface |
||
| 119 | */ |
||
| 120 | public function paginate(Parameters $params) { |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Returns one Localization with the given id |
||
| 150 | * |
||
| 151 | * @param mixed $id |
||
| 152 | * @return PayloadInterface |
||
| 153 | */ |
||
| 154 | public function read($id) { |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Removes LanguageVariant from Localization |
||
| 168 | * |
||
| 169 | * @param mixed $id |
||
| 170 | * @param mixed $data |
||
| 171 | * @return PayloadInterface |
||
| 172 | */ |
||
| 173 | public function removeLanguageVariant($id, $data) { |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Sets the Language id |
||
| 206 | * |
||
| 207 | * @param mixed $id |
||
| 208 | * @param mixed $extLangId |
||
| 209 | * @return PayloadInterface |
||
| 210 | */ |
||
| 211 | public function setExtLangId($id, $extLangId) { |
||
| 228 | |||
| 229 | /** |
||
| 230 | * Sets the Localization id |
||
| 231 | * |
||
| 232 | * @param mixed $id |
||
| 233 | * @param mixed $parentId |
||
| 234 | * @return PayloadInterface |
||
| 235 | */ |
||
| 236 | public function setParentId($id, $parentId) { |
||
| 253 | |||
| 254 | /** |
||
| 255 | * Sets the LanguageScript id |
||
| 256 | * |
||
| 257 | * @param mixed $id |
||
| 258 | * @param mixed $scriptId |
||
| 259 | * @return PayloadInterface |
||
| 260 | */ |
||
| 261 | public function setScriptId($id, $scriptId) { |
||
| 278 | |||
| 279 | /** |
||
| 280 | * Updates a Localization with the given idand the provided data |
||
| 281 | * |
||
| 282 | * @param mixed $id |
||
| 283 | * @param mixed $data |
||
| 284 | * @return PayloadInterface |
||
| 285 | */ |
||
| 286 | public function update($id, $data) { |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Updates LanguageVariant on Localization |
||
| 317 | * |
||
| 318 | * @param mixed $id |
||
| 319 | * @param mixed $data |
||
| 320 | * @return PayloadInterface |
||
| 321 | */ |
||
| 322 | public function updateLanguageVariant($id, $data) { |
||
| 355 | |||
| 356 | /** |
||
| 357 | * Implement this functionality at keeko\core\domain\LocalizationDomain |
||
| 358 | * |
||
| 359 | * @param LocalizationQuery $query |
||
| 360 | * @param mixed $filter |
||
| 361 | */ |
||
| 362 | abstract protected function applyFilter(LocalizationQuery $query, $filter); |
||
| 363 | |||
| 364 | /** |
||
| 365 | * Returns one Localization with the given id from cache |
||
| 366 | * |
||
| 367 | * @param mixed $id |
||
| 368 | * @return Localization|null |
||
| 369 | */ |
||
| 370 | protected function get($id) { |
||
| 382 | |||
| 383 | /** |
||
| 384 | * Returns the service container |
||
| 385 | * |
||
| 386 | * @return ServiceContainer |
||
| 387 | */ |
||
| 388 | abstract protected function getServiceContainer(); |
||
| 389 | } |
||
| 390 |
This check looks for access to methods that are not accessible from the current context.
If you need to make a method accessible to another context you can raise its visibility level in the defining class.