Complex classes like Share 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 Share, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
32 | class Share implements \OCP\Share\IShare { |
||
33 | |||
34 | /** @var string */ |
||
35 | private $id; |
||
36 | /** @var string */ |
||
37 | private $providerId; |
||
38 | /** @var Node */ |
||
39 | private $node; |
||
40 | /** @var int */ |
||
41 | private $fileId; |
||
42 | /** @var string */ |
||
43 | private $nodeType; |
||
44 | /** @var int */ |
||
45 | private $shareType; |
||
46 | /** @var string */ |
||
47 | private $sharedWith; |
||
48 | /** @var string */ |
||
49 | private $sharedBy; |
||
50 | /** @var string */ |
||
51 | private $shareOwner; |
||
52 | /** @var int */ |
||
53 | private $permissions; |
||
54 | /** @var \DateTime */ |
||
55 | private $expireDate; |
||
56 | /** @var string */ |
||
57 | private $password; |
||
58 | /** @var string */ |
||
59 | private $token; |
||
60 | /** @var int */ |
||
61 | private $parent; |
||
62 | /** @var string */ |
||
63 | private $target; |
||
64 | /** @var \DateTime */ |
||
65 | private $shareTime; |
||
66 | /** @var bool */ |
||
67 | private $mailSend; |
||
68 | /** @var string */ |
||
69 | private $name; |
||
70 | /** @var int */ |
||
71 | private $state; |
||
72 | /** @var bool */ |
||
73 | private $shouldHashPassword; |
||
74 | |||
75 | /** @var IRootFolder */ |
||
76 | private $rootFolder; |
||
77 | |||
78 | /** @var IUserManager */ |
||
79 | private $userManager; |
||
80 | |||
81 | public function __construct(IRootFolder $rootFolder, IUserManager $userManager) { |
||
87 | |||
88 | /** |
||
89 | * @inheritdoc |
||
90 | */ |
||
91 | public function setId($id) { |
||
107 | |||
108 | /** |
||
109 | * @inheritdoc |
||
110 | */ |
||
111 | public function getId() { |
||
114 | |||
115 | /** |
||
116 | * @inheritdoc |
||
117 | */ |
||
118 | public function getFullId() { |
||
124 | |||
125 | /** |
||
126 | * @inheritdoc |
||
127 | */ |
||
128 | public function setProviderId($id) { |
||
140 | |||
141 | /** |
||
142 | * @inheritdoc |
||
143 | */ |
||
144 | public function setNode(Node $node) { |
||
150 | |||
151 | /** |
||
152 | * @inheritdoc |
||
153 | */ |
||
154 | public function getNode() { |
||
178 | |||
179 | /** |
||
180 | * @inheritdoc |
||
181 | */ |
||
182 | public function setNodeId($fileId) { |
||
187 | |||
188 | /** |
||
189 | * @inheritdoc |
||
190 | */ |
||
191 | public function getNodeId() { |
||
198 | |||
199 | /** |
||
200 | * @inheritdoc |
||
201 | */ |
||
202 | public function setNodeType($type) { |
||
210 | |||
211 | /** |
||
212 | * @inheritdoc |
||
213 | */ |
||
214 | public function getNodeType() { |
||
222 | |||
223 | /** |
||
224 | * @inheritdoc |
||
225 | */ |
||
226 | public function setShareType($shareType) { |
||
230 | |||
231 | /** |
||
232 | * @inheritdoc |
||
233 | */ |
||
234 | public function getShareType() { |
||
237 | |||
238 | /** |
||
239 | * @inheritdoc |
||
240 | */ |
||
241 | public function setSharedWith($sharedWith) { |
||
248 | |||
249 | /** |
||
250 | * @inheritdoc |
||
251 | */ |
||
252 | public function getSharedWith() { |
||
255 | |||
256 | /** |
||
257 | * @inheritdoc |
||
258 | */ |
||
259 | public function setPermissions($permissions) { |
||
265 | |||
266 | /** |
||
267 | * @inheritdoc |
||
268 | */ |
||
269 | public function getPermissions() { |
||
272 | |||
273 | /** |
||
274 | * @inheritdoc |
||
275 | */ |
||
276 | public function setExpirationDate($expireDate) { |
||
282 | |||
283 | /** |
||
284 | * @inheritdoc |
||
285 | */ |
||
286 | public function getExpirationDate() { |
||
289 | |||
290 | /** |
||
291 | * @inheritdoc |
||
292 | */ |
||
293 | public function setSharedBy($sharedBy) { |
||
302 | |||
303 | /** |
||
304 | * @inheritdoc |
||
305 | */ |
||
306 | public function getSharedBy() { |
||
310 | |||
311 | /** |
||
312 | * @inheritdoc |
||
313 | */ |
||
314 | public function setShareOwner($shareOwner) { |
||
323 | |||
324 | /** |
||
325 | * @inheritdoc |
||
326 | */ |
||
327 | public function getShareOwner() { |
||
331 | |||
332 | /** |
||
333 | * @inheritdoc |
||
334 | */ |
||
335 | public function setPassword($password) { |
||
339 | |||
340 | /** |
||
341 | * @inheritdoc |
||
342 | */ |
||
343 | public function getPassword() { |
||
346 | |||
347 | /** |
||
348 | * @inheritdoc |
||
349 | */ |
||
350 | public function setToken($token) { |
||
354 | |||
355 | /** |
||
356 | * @inheritdoc |
||
357 | */ |
||
358 | public function getToken() { |
||
361 | |||
362 | /** |
||
363 | * Set the parent of this share |
||
364 | * |
||
365 | * @param int parent |
||
366 | * @return \OCP\Share\IShare |
||
367 | * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
||
368 | */ |
||
369 | public function setParent($parent) { |
||
373 | |||
374 | /** |
||
375 | * Get the parent of this share. |
||
376 | * |
||
377 | * @return int |
||
378 | * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
||
379 | */ |
||
380 | public function getParent() { |
||
383 | |||
384 | /** |
||
385 | * @inheritdoc |
||
386 | */ |
||
387 | public function setTarget($target) { |
||
391 | |||
392 | /** |
||
393 | * @inheritdoc |
||
394 | */ |
||
395 | public function getTarget() { |
||
398 | |||
399 | /** |
||
400 | * @inheritdoc |
||
401 | */ |
||
402 | public function setShareTime(\DateTime $shareTime) { |
||
406 | |||
407 | /** |
||
408 | * @inheritdoc |
||
409 | */ |
||
410 | public function getShareTime() { |
||
413 | |||
414 | /** |
||
415 | * @inheritdoc |
||
416 | */ |
||
417 | public function setMailSend($mailSend) { |
||
421 | |||
422 | /** |
||
423 | * @inheritdoc |
||
424 | */ |
||
425 | public function getMailSend() { |
||
428 | |||
429 | /** |
||
430 | * @inheritdoc |
||
431 | */ |
||
432 | public function setName($name) { |
||
436 | |||
437 | /** |
||
438 | * @inheritdoc |
||
439 | */ |
||
440 | public function getName() { |
||
443 | |||
444 | /** |
||
445 | * @inheritdoc |
||
446 | */ |
||
447 | public function setState($state) { |
||
451 | |||
452 | /** |
||
453 | * @inheritdoc |
||
454 | */ |
||
455 | public function getState() { |
||
458 | |||
459 | /** |
||
460 | * @inheritdoc |
||
461 | */ |
||
462 | public function getShouldHashPassword() { |
||
465 | |||
466 | /** |
||
467 | * @inheritdoc |
||
468 | */ |
||
469 | public function setShouldHashPassword($status) { |
||
472 | } |
||
473 |