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 | * Adds LanguageVariant to Localization |
||
28 | * |
||
29 | * @param mixed $id |
||
30 | * @param mixed $data |
||
31 | * @return PayloadInterface |
||
32 | */ |
||
33 | public function addLanguageVariant($id, $data) { |
||
63 | |||
64 | /** |
||
65 | * Creates a new Localization with the provided data |
||
66 | * |
||
67 | * @param mixed $data |
||
68 | * @return PayloadInterface |
||
69 | */ |
||
70 | public function create($data) { |
||
85 | |||
86 | /** |
||
87 | * Deletes a Localization with the given id |
||
88 | * |
||
89 | * @param mixed $id |
||
90 | * @return PayloadInterface |
||
91 | */ |
||
92 | public function delete($id) { |
||
109 | |||
110 | /** |
||
111 | * Returns a paginated result |
||
112 | * |
||
113 | * @param Parameters $params |
||
114 | * @return PayloadInterface |
||
115 | */ |
||
116 | public function paginate(Parameters $params) { |
||
143 | |||
144 | /** |
||
145 | * Returns one Localization with the given id |
||
146 | * |
||
147 | * @param mixed $id |
||
148 | * @return PayloadInterface |
||
149 | */ |
||
150 | public function read($id) { |
||
161 | |||
162 | /** |
||
163 | * Removes LanguageVariant from Localization |
||
164 | * |
||
165 | * @param mixed $id |
||
166 | * @param mixed $data |
||
167 | * @return PayloadInterface |
||
168 | */ |
||
169 | public function removeLanguageVariant($id, $data) { |
||
199 | |||
200 | /** |
||
201 | * Sets the Language id |
||
202 | * |
||
203 | * @param mixed $id |
||
204 | * @param mixed $extLanguageId |
||
205 | * @return PayloadInterface |
||
206 | */ |
||
207 | public function setExtLangId($id, $extLanguageId) { |
||
224 | |||
225 | /** |
||
226 | * Sets the Language id |
||
227 | * |
||
228 | * @param mixed $id |
||
229 | * @param mixed $languageId |
||
230 | * @return PayloadInterface |
||
231 | */ |
||
232 | public function setLanguageId($id, $languageId) { |
||
249 | |||
250 | /** |
||
251 | * Sets the Localization id |
||
252 | * |
||
253 | * @param mixed $id |
||
254 | * @param mixed $parentId |
||
255 | * @return PayloadInterface |
||
256 | */ |
||
257 | public function setParentId($id, $parentId) { |
||
274 | |||
275 | /** |
||
276 | * Sets the LanguageScript id |
||
277 | * |
||
278 | * @param mixed $id |
||
279 | * @param mixed $scriptId |
||
280 | * @return PayloadInterface |
||
281 | */ |
||
282 | public function setScriptId($id, $scriptId) { |
||
299 | |||
300 | /** |
||
301 | * Updates a Localization with the given idand the provided data |
||
302 | * |
||
303 | * @param mixed $id |
||
304 | * @param mixed $data |
||
305 | * @return PayloadInterface |
||
306 | */ |
||
307 | public function update($id, $data) { |
||
335 | |||
336 | /** |
||
337 | * Updates LanguageVariant on Localization |
||
338 | * |
||
339 | * @param mixed $id |
||
340 | * @param mixed $data |
||
341 | * @return PayloadInterface |
||
342 | */ |
||
343 | public function updateLanguageVariant($id, $data) { |
||
376 | |||
377 | /** |
||
378 | * Implement this functionality at keeko\core\domain\LocalizationDomain |
||
379 | * |
||
380 | * @param LocalizationQuery $query |
||
381 | * @param mixed $filter |
||
382 | */ |
||
383 | abstract protected function applyFilter(LocalizationQuery $query, $filter); |
||
384 | |||
385 | /** |
||
386 | * Returns one Localization with the given id from cache |
||
387 | * |
||
388 | * @param mixed $id |
||
389 | * @return Localization|null |
||
390 | */ |
||
391 | protected function get($id) { |
||
403 | |||
404 | /** |
||
405 | * Returns the service container |
||
406 | * |
||
407 | * @return ServiceContainer |
||
408 | */ |
||
409 | abstract protected function getServiceContainer(); |
||
410 | } |
||
411 |
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.