Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
23 | class Container extends Attachment implements |
||
|
|||
24 | AttachmentAwareInterface, |
||
25 | AttachmentContainerInterface, |
||
26 | ConfigurableInterface |
||
27 | { |
||
28 | use AttachmentAwareTrait; |
||
29 | use AttachmentContainerTrait; |
||
30 | use ConfigurableAttachmentsTrait; |
||
31 | |||
32 | /** |
||
33 | * Inject dependencies from a DI Container. |
||
34 | * |
||
35 | * @param ServiceContainer $container A dependencies container instance. |
||
36 | * @return void |
||
37 | */ |
||
38 | View Code Duplication | protected function setDependencies(ServiceContainer $container) |
|
48 | |||
49 | /** |
||
50 | * Retrieve the objects associated to the current object. |
||
51 | * |
||
52 | * @param mixed ...$args Filter the attachments; |
||
53 | * options accepted by {@see AttachmentAwareTrait::attachments()}. |
||
54 | * @return Collection|Attachment[] |
||
55 | */ |
||
56 | public function attachments(...$args) |
||
71 | |||
72 | /** |
||
73 | * Event called before _deleting_ the attachment. |
||
74 | * |
||
75 | * @return boolean |
||
76 | * @see Charcoal\Attachment\Traits\AttachmentAwareTrait::removeJoins |
||
77 | * @see Charcoal\Source\StorableTrait::preDelete() For the "create" Event. |
||
78 | */ |
||
79 | public function preDelete() |
||
88 | } |
||
89 |