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 |
||
| 26 | class LinkResource extends GenericResource implements PuliResource |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | private $targetPath; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @param string $targetPath |
||
| 35 | * @param string|null $path |
||
| 36 | */ |
||
| 37 | 40 | public function __construct($targetPath, $path = null) |
|
| 43 | |||
| 44 | /** |
||
| 45 | * Return this link target path. |
||
| 46 | * |
||
| 47 | * @return string |
||
| 48 | */ |
||
| 49 | 32 | public function getTargetPath() |
|
| 53 | |||
| 54 | /** |
||
| 55 | * Return the resource associated in the link repository to this link target path. |
||
| 56 | * |
||
| 57 | * @param boolean $followLinks Whether to fully follow links or not. |
||
| 58 | * |
||
| 59 | * @return PuliResource |
||
| 60 | */ |
||
| 61 | 21 | public function getTarget($followLinks = false) |
|
| 79 | |||
| 80 | /** |
||
| 81 | * {@inheritdoc} |
||
| 82 | */ |
||
| 83 | View Code Duplication | public function getChild($relPath) |
|
| 91 | |||
| 92 | /** |
||
| 93 | * {@inheritdoc} |
||
| 94 | */ |
||
| 95 | public function hasChild($relPath) |
||
| 103 | |||
| 104 | /** |
||
| 105 | * {@inheritdoc} |
||
| 106 | */ |
||
| 107 | 10 | public function hasChildren() |
|
| 115 | |||
| 116 | /** |
||
| 117 | * {@inheritdoc} |
||
| 118 | */ |
||
| 119 | 7 | View Code Duplication | public function listChildren() |
| 133 | } |
||
| 134 |