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  | 
            ||
| 27 | class GenericResource implements PuliResource  | 
            ||
| 28 | { | 
            ||
| 29 | /**  | 
            ||
| 30 | * @var ResourceRepository  | 
            ||
| 31 | */  | 
            ||
| 32 | private $repo;  | 
            ||
| 33 | |||
| 34 | /**  | 
            ||
| 35 | * @var string  | 
            ||
| 36 | */  | 
            ||
| 37 | private $path;  | 
            ||
| 38 | |||
| 39 | /**  | 
            ||
| 40 | * @var string  | 
            ||
| 41 | */  | 
            ||
| 42 | private $repoPath;  | 
            ||
| 43 | |||
| 44 | /**  | 
            ||
| 45 | * Creates a new resource.  | 
            ||
| 46 | *  | 
            ||
| 47 | * @param string|null $path The path of the resource.  | 
            ||
| 48 | */  | 
            ||
| 49 | 733 | public function __construct($path = null)  | 
            |
| 54 | |||
| 55 | /**  | 
            ||
| 56 |      * {@inheritdoc} | 
            ||
| 57 | */  | 
            ||
| 58 | 307 | public function getPath()  | 
            |
| 62 | |||
| 63 | /**  | 
            ||
| 64 |      * {@inheritdoc} | 
            ||
| 65 | */  | 
            ||
| 66 | 317 | public function getName()  | 
            |
| 70 | |||
| 71 | /**  | 
            ||
| 72 |      * {@inheritdoc} | 
            ||
| 73 | */  | 
            ||
| 74 | 4 | View Code Duplication | public function getChild($relPath)  | 
            
| 82 | |||
| 83 | /**  | 
            ||
| 84 |      * {@inheritdoc} | 
            ||
| 85 | */  | 
            ||
| 86 | 3 | public function hasChild($relPath)  | 
            |
| 94 | |||
| 95 | /**  | 
            ||
| 96 |      * {@inheritdoc} | 
            ||
| 97 | */  | 
            ||
| 98 | 3 | public function hasChildren()  | 
            |
| 106 | |||
| 107 | /**  | 
            ||
| 108 |      * {@inheritdoc} | 
            ||
| 109 | */  | 
            ||
| 110 | 6 | View Code Duplication | public function listChildren()  | 
            
| 124 | |||
| 125 | /**  | 
            ||
| 126 |      * {@inheritdoc} | 
            ||
| 127 | */  | 
            ||
| 128 | public function getStack()  | 
            ||
| 136 | |||
| 137 | /**  | 
            ||
| 138 |      * {@inheritdoc} | 
            ||
| 139 | */  | 
            ||
| 140 | public function getMetadata()  | 
            ||
| 144 | |||
| 145 | /**  | 
            ||
| 146 |      * {@inheritdoc} | 
            ||
| 147 | */  | 
            ||
| 148 | 439 | public function attachTo(ResourceRepository $repo, $path = null)  | 
            |
| 157 | |||
| 158 | /**  | 
            ||
| 159 |      * {@inheritdoc} | 
            ||
| 160 | */  | 
            ||
| 161 | 25 | public function detach()  | 
            |
| 165 | |||
| 166 | /**  | 
            ||
| 167 |      * {@inheritdoc} | 
            ||
| 168 | */  | 
            ||
| 169 | 245 | public function getRepository()  | 
            |
| 173 | |||
| 174 | /**  | 
            ||
| 175 |      * {@inheritdoc} | 
            ||
| 176 | */  | 
            ||
| 177 | 128 | public function getRepositoryPath()  | 
            |
| 181 | |||
| 182 | /**  | 
            ||
| 183 |      * {@inheritdoc} | 
            ||
| 184 | */  | 
            ||
| 185 | 287 | public function isAttached()  | 
            |
| 189 | |||
| 190 | /**  | 
            ||
| 191 |      * {@inheritdoc} | 
            ||
| 192 | */  | 
            ||
| 193 | 56 | public function createReference($path)  | 
            |
| 200 | |||
| 201 | /**  | 
            ||
| 202 |      * {@inheritdoc} | 
            ||
| 203 | */  | 
            ||
| 204 | 84 | public function isReference()  | 
            |
| 208 | |||
| 209 | /**  | 
            ||
| 210 |      * {@inheritdoc} | 
            ||
| 211 | */  | 
            ||
| 212 | 39 | public function serialize()  | 
            |
| 220 | |||
| 221 | /**  | 
            ||
| 222 |      * {@inheritdoc} | 
            ||
| 223 | */  | 
            ||
| 224 | 35 | public function unserialize($string)  | 
            |
| 230 | |||
| 231 | /**  | 
            ||
| 232 | * Invoked before serializing a resource.  | 
            ||
| 233 | *  | 
            ||
| 234 | * Override this method if you want to serialize custom data in subclasses.  | 
            ||
| 235 | *  | 
            ||
| 236 | * @param array $data The data to serialize. Add custom data at the end of  | 
            ||
| 237 | * the array.  | 
            ||
| 238 | */  | 
            ||
| 239 | 39 | protected function preSerialize(array &$data)  | 
            |
| 244 | |||
| 245 | /**  | 
            ||
| 246 | * Invoked after unserializing a resource.  | 
            ||
| 247 | *  | 
            ||
| 248 | * Override this method if you want to unserialize custom data in  | 
            ||
| 249 | * subclasses.  | 
            ||
| 250 | *  | 
            ||
| 251 | * @param array $data The unserialized data. Pop your custom data from the  | 
            ||
| 252 | * end of the array before calling the parent method.  | 
            ||
| 253 | */  | 
            ||
| 254 | 35 | protected function postUnserialize(array $data)  | 
            |
| 259 | }  | 
            ||
| 260 |