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 | 58 | public function __construct($targetPath, $path = null) |
|
| 38 | { |
||
| 39 | 58 | parent::__construct($path); |
|
| 40 | |||
| 41 | 58 | $this->targetPath = $targetPath; |
|
| 42 | 58 | } |
|
| 43 | |||
| 44 | /** |
||
| 45 | * @return string |
||
| 46 | */ |
||
| 47 | 24 | public function getTargetPath() |
|
| 51 | |||
| 52 | /** |
||
| 53 | * {@inheritdoc} |
||
| 54 | */ |
||
| 55 | 8 | public function getTarget() |
|
| 63 | |||
| 64 | /** |
||
| 65 | * {@inheritdoc} |
||
| 66 | */ |
||
| 67 | 4 | View Code Duplication | public function getChild($relPath) |
| 75 | |||
| 76 | /** |
||
| 77 | * {@inheritdoc} |
||
| 78 | */ |
||
| 79 | 3 | public function hasChild($relPath) |
|
| 87 | |||
| 88 | /** |
||
| 89 | * {@inheritdoc} |
||
| 90 | */ |
||
| 91 | 11 | public function hasChildren() |
|
| 99 | |||
| 100 | /** |
||
| 101 | * {@inheritdoc} |
||
| 102 | */ |
||
| 103 | 5 | View Code Duplication | public function listChildren() |
| 117 | |||
| 118 | 7 | protected function preSerialize(array &$data) |
|
| 124 | |||
| 125 | 7 | protected function postUnserialize(array $data) |
|
| 131 | } |
||
| 132 |