Complex classes like GroupDomainTrait 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 GroupDomainTrait, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
26 | trait GroupDomainTrait { |
||
27 | |||
28 | /** |
||
29 | */ |
||
30 | protected $pool; |
||
31 | |||
32 | /** |
||
33 | * Adds Action to Group |
||
34 | * |
||
35 | * @param mixed $id |
||
36 | * @param mixed $data |
||
37 | * @return PayloadInterface |
||
38 | */ |
||
39 | public function addAction($id, $data) { |
||
69 | |||
70 | /** |
||
71 | * Adds User to Group |
||
72 | * |
||
73 | * @param mixed $id |
||
74 | * @param mixed $data |
||
75 | * @return PayloadInterface |
||
76 | */ |
||
77 | public function addUser($id, $data) { |
||
107 | |||
108 | /** |
||
109 | * Creates a new Group with the provided data |
||
110 | * |
||
111 | * @param mixed $data |
||
112 | * @return PayloadInterface |
||
113 | */ |
||
114 | public function create($data) { |
||
129 | |||
130 | /** |
||
131 | * Deletes a Group with the given id |
||
132 | * |
||
133 | * @param mixed $id |
||
134 | * @return PayloadInterface |
||
135 | */ |
||
136 | public function delete($id) { |
||
153 | |||
154 | /** |
||
155 | * Returns a paginated result |
||
156 | * |
||
157 | * @param Parameters $params |
||
158 | * @return PayloadInterface |
||
159 | */ |
||
160 | public function paginate(Parameters $params) { |
||
187 | |||
188 | /** |
||
189 | * Returns one Group with the given id |
||
190 | * |
||
191 | * @param mixed $id |
||
192 | * @return PayloadInterface |
||
193 | */ |
||
194 | public function read($id) { |
||
205 | |||
206 | /** |
||
207 | * Removes Action from Group |
||
208 | * |
||
209 | * @param mixed $id |
||
210 | * @param mixed $data |
||
211 | * @return PayloadInterface |
||
212 | */ |
||
213 | public function removeAction($id, $data) { |
||
243 | |||
244 | /** |
||
245 | * Removes User from Group |
||
246 | * |
||
247 | * @param mixed $id |
||
248 | * @param mixed $data |
||
249 | * @return PayloadInterface |
||
250 | */ |
||
251 | public function removeUser($id, $data) { |
||
281 | |||
282 | /** |
||
283 | * Updates a Group with the given idand the provided data |
||
284 | * |
||
285 | * @param mixed $id |
||
286 | * @param mixed $data |
||
287 | * @return PayloadInterface |
||
288 | */ |
||
289 | public function update($id, $data) { |
||
317 | |||
318 | /** |
||
319 | * Updates Action on Group |
||
320 | * |
||
321 | * @param mixed $id |
||
322 | * @param mixed $data |
||
323 | * @return PayloadInterface |
||
324 | */ |
||
325 | public function updateAction($id, $data) { |
||
358 | |||
359 | /** |
||
360 | * Updates User on Group |
||
361 | * |
||
362 | * @param mixed $id |
||
363 | * @param mixed $data |
||
364 | * @return PayloadInterface |
||
365 | */ |
||
366 | public function updateUser($id, $data) { |
||
399 | |||
400 | /** |
||
401 | * Implement this functionality at keeko\core\domain\GroupDomain |
||
402 | * |
||
403 | * @param GroupQuery $query |
||
404 | * @param mixed $filter |
||
405 | */ |
||
406 | abstract protected function applyFilter(GroupQuery $query, $filter); |
||
407 | |||
408 | /** |
||
409 | * Returns one Group with the given id from cache |
||
410 | * |
||
411 | * @param mixed $id |
||
412 | * @return Group|null |
||
413 | */ |
||
414 | protected function get($id) { |
||
426 | |||
427 | /** |
||
428 | * Returns the service container |
||
429 | * |
||
430 | * @return ServiceContainer |
||
431 | */ |
||
432 | abstract protected function getServiceContainer(); |
||
433 | } |
||
434 |
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.