| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the Runalyze DEM Reader. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * (c) RUNALYZE <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * This source file is subject to the MIT license that is bundled | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * with this source code in the file LICENSE. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | namespace Runalyze\DEM\Provider\GeoTIFF; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Runalyze\DEM\Exception\InvalidArgumentException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $this->loadTileReferencesFor($latitude, $longitude); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         return sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             $this->FilenameFormat, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             $this->CurrentTileVerticalReference < 0 ? 's' : 'n', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             abs($this->CurrentTileVerticalReference), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             $this->CurrentTileHorizontalReference < 0 ? 'w' : 'e', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             abs($this->CurrentTileHorizontalReference) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * @param float $latitude | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * @param float $longitude | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 46 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |     protected function loadTileReferencesFor($latitude, $longitude) | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |         $this->CurrentTileVerticalReference = floor($latitude / static::DEGREES_PER_TILE); | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |         $this->CurrentTileHorizontalReference = floor($longitude / static::DEGREES_PER_TILE); | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |         $this->CurrentTileLatitude = $this->CurrentTileVerticalReference; | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |         $this->CurrentTileLongitude = $this->CurrentTileHorizontalReference; | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         return $this->ResourceReader->getExactRowAndColFor( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             abs($this->CurrentTileLatitude + 1 - $latitude) / static::DEGREES_PER_TILE, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             abs($longitude - $this->CurrentTileLongitude) / static::DEGREES_PER_TILE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 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.