| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace DavidePastore\Ipinfo; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * ipinfo.io service wrapper. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @author davidepastore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | class Ipinfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |      * The base url of the ipinfo service. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     const BASE_URL = 'http://ipinfo.io/'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * The ip string. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     const IP = 'ip'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * The hostname string. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     const HOSTNAME = 'hostname'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * The loc string. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     const LOC = 'loc'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * The org string. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     const ORG = 'org'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * The city string. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     const CITY = 'city'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * The region string. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     const REGION = 'region'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * The country string. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     const COUNTRY = 'country'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * The phone string. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     const PHONE = 'phone'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * The geo string. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     const GEO = 'geo'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * The postal string. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     const POSTAL = 'postal'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * All the settings. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     protected $settings; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * Create an Ipinfo instance. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * @param array $settings An array with all the settings. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      *                        Supported keys are: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      *                        - token: string the developer token; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      *                        - debug: boolean active or not the debug. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 | 8 |  |     public function __construct($settings = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         //Merge user settings | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 | 8 |  |         $this->settings = array_merge(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 | 8 |  |                 'token' => '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 | 8 |  |                 'debug' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 | 8 |  |         ), $settings); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 | 8 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |      * Get all the info about your own ip address. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |      * @return \DavidePastore\Ipinfo\Host The Host object with all the info. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 | 1 |  |     public function getYourOwnIpDetails() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 | 1 |  |         $response = $this->makeCurlRequest($this::BASE_URL.'json'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 | 1 |  |         $response = $this->jsonDecodeResponse($response); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 | 1 |  |         return new Host($response); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |      * Get all the info about an ip address. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |      * @param string $ipAddress The ip address. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |      * @return \DavidePastore\Ipinfo\Host The Host object with all the info. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 | 2 |  |     public function getFullIpDetails($ipAddress) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 | 2 |  |         $response = $this->makeCurlRequest($this::BASE_URL.$ipAddress); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 | 2 |  |         $response = $this->jsonDecodeResponse($response); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 | 2 |  |         return new Host($response); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |      * Get a specific field value. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |      * @param string $ipAddress The ip address. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |      * @param string $field     The field. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |      * @return string|\DavidePastore\Ipinfo\Host The value of the given field for the given ip. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |      *                                           This could returns an Host object if you call it with for the field | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |      *                                           \DavidePastore\Ipinfo\Ipinfo::GEO. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 151 | 4 | View Code Duplication |     public function getSpecificField($ipAddress, $field) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 | 4 |  |         $response = $this->makeCurlRequest($this::BASE_URL.$ipAddress.'/'.$field); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 | 4 |  |         $response = $this->checkGeo($field, $response); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 | 4 |  |         return $response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |      * Get a specific field value of your own ip address. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |      * @param string $field The field. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |      * @return string|\DavidePastore\Ipinfo\Host The value of the given field for your own ip. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |      *                                           This could returns an Host object if you call it with for the field | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |      *                                           \DavidePastore\Ipinfo\Ipinfo::GEO. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 168 | 1 | View Code Duplication |     public function getYourOwnIpSpecificField($field) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 | 1 |  |         $response = $this->makeCurlRequest($this::BASE_URL.$field); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 | 1 |  |         $response = $this->checkGeo($field, $response); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 | 1 |  |         return $response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |      * Use the /geo call to get just the geolocation information, which will often be | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |      * faster than getting the full response. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |      * @param string $ipAddress The ip address. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |      * @return \DavidePastore\Ipinfo\Host | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 | 1 |  |     public function getIpGeoDetails($ipAddress) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 | 1 |  |         return $this->getSpecificField($ipAddress, $this::GEO); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |      * Check if the response is GEO and set the parameters accordingly. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |      * @param string $field    The field value. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |      * @param string $response The response from the server. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |      * @return Ambigous <\DavidePastore\Ipinfo\Host, string> Returns an Host object if the request is | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |      *                  of the GEO type, a string otherwise. If the field value is different from the GEO type, it will | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |      *                  delete the last character ('\n'). | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 198 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 199 | 5 |  |     private function checkGeo($field, $response) | 
            
                                                                        
                            
            
                                    
            
            
                | 200 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 201 | 5 |  |         if ($field == $this::GEO) { | 
            
                                                                        
                            
            
                                    
            
            
                | 202 | 1 |  |             $response = $this->jsonDecodeResponse($response); | 
            
                                                                        
                            
            
                                    
            
            
                | 203 | 1 |  |             $response = new Host($response); | 
            
                                                                        
                            
            
                                    
            
            
                | 204 | 1 |  |         } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 205 | 4 |  |             $response = substr($response, 0, -1); | 
            
                                                                        
                            
            
                                    
            
            
                | 206 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 207 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 208 | 5 |  |         return $response; | 
            
                                                                        
                            
            
                                    
            
            
                | 209 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |      * Make a curl request. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |      * @param string $address The address of the request. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |      * @return string Returns the response from the request. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 | 8 |  |     private function makeCurlRequest($address) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 | 8 |  |         $curl = curl_init(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 | 8 |  |         if (!empty($this->settings['token'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 | 1 |  |             $address .= '?token='.$this->settings['token']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 | 1 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 | 8 |  |         if ($this->settings['debug']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 | 1 |  |             echo 'Request address: '.$address."\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 | 1 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 | 8 |  |         curl_setopt_array($curl, array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 | 8 |  |             CURLOPT_RETURNTRANSFER => 1, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 | 8 |  |             CURLOPT_URL => $address, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 | 8 |  |         )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 | 8 |  |         $response = curl_exec($curl); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 | 8 |  |         curl_close($curl); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 | 8 |  |         return $response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |      * Returns the json decoded associative array. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |      * @param  string $response Response from the http call. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |      * @return array           Returns the associative array with the response. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 | 4 |  |     private function jsonDecodeResponse($response) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 | 4 |  |         if($response){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 | 4 |  |             $response = json_decode($response, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 | 4 |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |             $response = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 | 4 |  |         return $response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 256 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 257 |  |  |  | 
            
                        
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.