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 | abstract class SetAbstract extends CollectionAbstract implements SetInterface |
||
24 | { |
||
25 | /** |
||
26 | * Removes all of this collection's elements that are also contained in the specified collection (optional operation). |
||
27 | * @param CollectionInterface $collection |
||
28 | */ |
||
29 | public function removeAll(CollectionInterface $collection) |
||
63 | |||
64 | /** |
||
65 | * Returns the hash code value for this set. |
||
66 | * The hash code of a set is defined to be the sum of the hash codes of |
||
67 | * the elements in the set, where the hash code of a null element is defined to be zero. |
||
68 | * This ensures that s1.equals(s2) implies that s1.hashCode()==s2.hashCode() |
||
69 | * for any two sets s1 and s2, as required by the general contract of Collection.hashCode(). |
||
70 | * @return string |
||
71 | */ |
||
72 | public function hashCode() |
||
84 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.