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 SRTM4Provider extends AbstractGeoTIFFProvider |
||
17 | { |
||
18 | /** @var int */ |
||
19 | const MAX_LATITUDE = 60; |
||
20 | |||
21 | /** @var int */ |
||
22 | const MAX_LONGITUDE = 180; |
||
23 | |||
24 | /** @var float */ |
||
25 | const DEGREES_PER_TILE = 5.0; |
||
26 | |||
27 | /** @var float */ |
||
28 | protected $CurrentTileHorizontalReference; |
||
29 | |||
30 | /** @var float */ |
||
31 | protected $CurrentTileVerticalReference; |
||
32 | |||
33 | /** @var float top left latitude */ |
||
34 | protected $CurrentTileLatitude; |
||
35 | |||
36 | /** @var float top left longitude */ |
||
37 | protected $CurrentTileLongitude; |
||
38 | |||
39 | /** @var string */ |
||
40 | protected $FilenameFormat = 'srtm_%02d_%02d.tif'; |
||
41 | |||
42 | /** @var GeoTIFFReader */ |
||
43 | protected $ResourceReader; |
||
44 | |||
45 | public function initResourceReader() |
||
49 | |||
50 | /** |
||
51 | * @param $format |
||
52 | */ |
||
53 | public function setFilenameFormat($format) |
||
57 | |||
58 | /** |
||
59 | * @param float $latitude |
||
60 | * @param float $longitude |
||
61 | * @return string |
||
62 | * @throws InvalidArgumentException |
||
63 | */ |
||
64 | protected function getFilenameFor($latitude, $longitude) |
||
70 | |||
71 | /** |
||
72 | * @param float $latitude |
||
73 | * @param float $longitude |
||
74 | */ |
||
75 | protected function loadTileReferencesFor($latitude, $longitude) |
||
96 | |||
97 | /** |
||
98 | * @param float $latitude |
||
99 | * @param float $longitude |
||
100 | * @return float[] array(row, col) |
||
101 | */ |
||
102 | View Code Duplication | protected function getExactRowAndColFor($latitude, $longitude) |
|
109 | } |
||
110 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.