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 SplFileInfoPatch implements ClassPatchInterface |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * Supports everything that extends SplFileInfo. |
||
| 27 | * |
||
| 28 | * @param ClassNode $node |
||
| 29 | * |
||
| 30 | * @return bool |
||
| 31 | */ |
||
| 32 | public function supports(ClassNode $node) |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Updated constructor code to call parent one with dummy file argument. |
||
| 44 | * |
||
| 45 | * @param ClassNode $node |
||
| 46 | */ |
||
| 47 | public function apply(ClassNode $node) |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Returns patch priority, which determines when patch will be applied. |
||
| 81 | * |
||
| 82 | * @return int Priority number (higher - earlier) |
||
| 83 | */ |
||
| 84 | public function getPriority() |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @param ClassNode $node |
||
| 91 | * @return boolean |
||
| 92 | */ |
||
| 93 | private function nodeIsDirectoryIterator(ClassNode $node) |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @param ClassNode $node |
||
| 103 | * @return boolean |
||
| 104 | */ |
||
| 105 | private function nodeIsSplFileObject(ClassNode $node) |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @param ClassNode $node |
||
| 115 | * @return boolean |
||
| 116 | */ |
||
| 117 | private function nodeIsSymfonySplFileInfo(ClassNode $node) |
||
| 123 | } |
||
| 124 |
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.