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 |
||
16 | class SRTM1ArcSecondProvider extends SRTM4Provider |
||
17 | { |
||
18 | /** @var float */ |
||
19 | const DEGREES_PER_TILE = 1.0; |
||
20 | |||
21 | /** @var string */ |
||
22 | protected $FilenameFormat = '%s%02d_%s%03d.tif'; |
||
23 | |||
24 | /** |
||
25 | * @param float $latitude |
||
26 | * @param float $longitude |
||
27 | * @return string |
||
28 | * @throws InvalidArgumentException |
||
29 | */ |
||
30 | protected function getFilenameFor($latitude, $longitude) |
||
42 | |||
43 | /** |
||
44 | * @param float $latitude |
||
45 | * @param float $longitude |
||
46 | */ |
||
47 | protected function loadTileReferencesFor($latitude, $longitude) |
||
55 | |||
56 | /** |
||
57 | * @param float $latitude |
||
58 | * @param float $longitude |
||
59 | * @return float[] array(row, col) |
||
60 | */ |
||
61 | View Code Duplication | protected function getExactRowAndColFor($latitude, $longitude) |
|
68 | } |
||
69 |
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.