| Conditions | 4 | 
| Paths | 5 | 
| Total Lines | 66 | 
| Code Lines | 53 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php  | 
            ||
| 147 | public function azureProvisioning():bool  | 
            ||
| 148 |     { | 
            ||
| 149 | $baseUrl = 'http://168.63.129.16/machine';  | 
            ||
| 150 | $timeout = 4;  | 
            ||
| 151 | |||
| 152 | $curl = curl_init();  | 
            ||
| 153 |         $url  = "{$baseUrl}?comp=goalstate"; | 
            ||
| 154 | curl_setopt($curl, CURLOPT_URL, $url);  | 
            ||
| 155 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);  | 
            ||
| 156 | curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);  | 
            ||
| 157 | curl_setopt($curl, CURLOPT_HTTPHEADER, ['x-ms-version: 2012-11-30']);  | 
            ||
| 158 | $resultRequest = curl_exec($curl);  | 
            ||
| 159 | $http_code = (int)curl_getinfo($curl, CURLINFO_HTTP_CODE);  | 
            ||
| 160 | curl_close($curl);  | 
            ||
| 161 | |||
| 162 |         if($http_code === 0){ | 
            ||
| 163 | $setting = new PbxSettings();  | 
            ||
| 164 | $setting->key = self::PBX_SETTING_KEY;  | 
            ||
| 165 | $setting->save();  | 
            ||
| 166 | $setting->value = '0';  | 
            ||
| 167 | unset($setting);  | 
            ||
| 168 | // It is not azure;  | 
            ||
| 169 | return false;  | 
            ||
| 170 | }  | 
            ||
| 171 | |||
| 172 | $xml = simplexml_load_string($resultRequest);  | 
            ||
| 173 | $xmlDocument = $this->getAzureXmlResponse($xml->Container->ContainerId, $xml->Container->RoleInstanceList->RoleInstance->InstanceId);  | 
            ||
| 174 |         $url="{$baseUrl}?comp=health"; | 
            ||
| 175 | $headers = [  | 
            ||
| 176 | 'x-ms-version: 2012-11-30',  | 
            ||
| 177 | 'x-ms-agent-name: WALinuxAgent',  | 
            ||
| 178 | 'Content-Type: text/xml;charset=utf-8',  | 
            ||
| 179 | ];  | 
            ||
| 180 | |||
| 181 | $curl = curl_init();  | 
            ||
| 182 | curl_setopt($curl, CURLOPT_URL, $url);  | 
            ||
| 183 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);  | 
            ||
| 184 | curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);  | 
            ||
| 185 | curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);  | 
            ||
| 186 | curl_setopt($curl, CURLOPT_POST, true);  | 
            ||
| 187 | curl_setopt($curl, CURLOPT_POSTFIELDS, $xmlDocument);  | 
            ||
| 188 | |||
| 189 | curl_exec($curl);  | 
            ||
| 190 | $http_code = (int)curl_getinfo($curl, CURLINFO_HTTP_CODE);  | 
            ||
| 191 | $result = false;  | 
            ||
| 192 |         if($http_code === 200){ | 
            ||
| 193 | $result = true;  | 
            ||
| 194 | }  | 
            ||
| 195 | $curl = curl_init();  | 
            ||
| 196 | $url = "http://169.254.169.254/metadata/instance?api-version=2020-09-01";  | 
            ||
| 197 | curl_setopt($curl, CURLOPT_URL, $url);  | 
            ||
| 198 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);  | 
            ||
| 199 | curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);  | 
            ||
| 200 | curl_setopt($curl, CURLOPT_HTTPHEADER, ['Metadata:true']);  | 
            ||
| 201 | $resultRequest = curl_exec($curl);  | 
            ||
| 202 | curl_close($curl);  | 
            ||
| 203 | |||
| 204 | $arrKeys = [];  | 
            ||
| 205 | $jsonData = json_decode($resultRequest, true);  | 
            ||
| 206 | $publicKeys = $jsonData['compute']['publicKeys']??[];  | 
            ||
| 207 |         foreach ($publicKeys as $keeData){ | 
            ||
| 208 | $arrKeys[]= $keeData['keyData'];  | 
            ||
| 209 | }  | 
            ||
| 210 | $this->updateSSHKeys(implode(PHP_EOL, $arrKeys));  | 
            ||
| 211 | $this->updateSshPassword();  | 
            ||
| 212 | return $result;  | 
            ||
| 213 | }  | 
            ||
| 238 | }  |