@@ -10,19 +10,12 @@ class VultrAPI
10
10
protected $ server_create_details = [];
11
11
protected $ call_data ;
12
12
13
- public function __construct ( bool $ json_header = false )
13
+ protected function apiKeyHeader (): array
14
14
{
15
- if ($ json_header ) {
16
- header ('Content-Type: application/json ' );
17
- }
15
+ return array ("Authorization: Bearer " . self ::API_KEY , "Content-Type: application/json " );
18
16
}
19
17
20
- public function apiKeyHeader (): array
21
- {
22
- return array ("Authorization: Bearer " . self ::API_KEY . "" , "Content-Type: application/json " );
23
- }
24
-
25
- public function doCurl (string $ url , string $ type = 'GET ' , bool $ return_http_code = false , array $ headers = [], array $ post_fields = [])
18
+ protected function doCurl (string $ url , string $ type = 'GET ' , bool $ return_http_code = false , array $ headers = [], array $ post_fields = [])
26
19
{
27
20
$ crl = curl_init (self ::API_URL . $ url );
28
21
curl_setopt ($ crl , CURLOPT_CUSTOMREQUEST , $ type );
@@ -48,13 +41,11 @@ public function doCurl(string $url, string $type = 'GET', bool $return_http_code
48
41
curl_close ($ crl );
49
42
if ($ return_http_code ) {
50
43
return $ http_response_code ;
51
- } else {
52
- if ($ http_response_code == 200 || $ http_response_code == 201 || $ http_response_code == 202 ) {
53
- return $ this ->call_data = $ call_response ;//Return data
54
- } else {
55
- return $ this ->call_data = array ('http_response_code ' => $ http_response_code );//Call failed
56
- }
57
44
}
45
+ if ($ http_response_code == 200 || $ http_response_code == 201 || $ http_response_code == 202 ) {
46
+ return $ this ->call_data = $ call_response ;//Return data
47
+ }
48
+ return $ this ->call_data = array ('http_response_code ' => $ http_response_code );//Call failed
58
49
}
59
50
60
51
public function setSubid (string $ instance_id ): void
@@ -64,7 +55,7 @@ public function setSubid(string $instance_id): void
64
55
65
56
public function checkSubidSet ()
66
57
{
67
- if (is_null ( $ this -> instance_id ) || empty ($ this ->instance_id )) {
58
+ if (empty ($ this ->instance_id )) {
68
59
return array ("No subid is set, it is needed to perform this action. " );
69
60
}
70
61
}
@@ -149,11 +140,7 @@ public function instanceUpdate(array $values = [])
149
140
public function instanceReinstall (string $ hostname = '' )
150
141
{
151
142
$ this ->checkSubidSet ();
152
- if (!empty ($ hostname )) {
153
- $ post = array ("hostname " => $ hostname );
154
- } else {
155
- $ post = array ();
156
- }
143
+ (!empty ($ hostname )) ? $ post = array ("hostname " => $ hostname ) : $ post = array ();
157
144
return $ this ->doCurl ("v2/instances/ $ this ->instance_id /reinstall " , 'POST ' , true , $ this ->apiKeyHeader (), $ post );
158
145
}
159
146
@@ -365,20 +352,20 @@ public function serverCreatePlan(string $plan_id)
365
352
366
353
public function serverCreateType (string $ type = 'OS ' , string $ type_id = '1 ' )
367
354
{
368
- if ($ type == 'OS ' ) {
355
+ if ($ type === 'OS ' ) {
369
356
$ this ->server_create_details = array_merge ($ this ->server_create_details , array (
370
357
"os_id " => $ type_id
371
358
));
372
- } elseif ($ type == 'SNAPSHOT ' ) {
359
+ } elseif ($ type === 'SNAPSHOT ' ) {
373
360
$ this ->server_create_details = array_merge ($ this ->server_create_details , array (
374
361
"snapshot_id " => $ type_id
375
362
));
376
- } elseif ($ type == 'ISO ' ) {
363
+ } elseif ($ type === 'ISO ' ) {
377
364
$ this ->server_create_details = array_merge ($ this ->server_create_details , array (
378
365
"os_id " => 159 ,
379
366
"iso_id " => $ type_id
380
367
));
381
- } elseif ($ type == 'APP ' ) {
368
+ } elseif ($ type === 'APP ' ) {
382
369
$ this ->server_create_details = array_merge ($ this ->server_create_details , array (
383
370
"os_id " => 186 ,
384
371
"app_id " => $ type_id
@@ -913,26 +900,24 @@ public function s3keyRegenObjectStorage(string $obj_id)
913
900
*/
914
901
public function convertBytes (int $ bytes , string $ convert_to = 'GB ' , bool $ format = true , int $ decimals = 2 )
915
902
{
916
- if ($ convert_to == 'GB ' ) {
903
+ if ($ convert_to === 'GB ' ) {
917
904
$ value = ($ bytes / 1073741824 );
918
- } elseif ($ convert_to == 'MB ' ) {
905
+ } elseif ($ convert_to === 'MB ' ) {
919
906
$ value = ($ bytes / 1048576 );
920
- } elseif ($ convert_to == 'KB ' ) {
907
+ } elseif ($ convert_to === 'KB ' ) {
921
908
$ value = ($ bytes / 1024 );
922
909
} else {
923
910
$ value = $ bytes ;
924
911
}
925
912
if ($ format ) {
926
913
return number_format ($ value , $ decimals );
927
- } else {
928
- return $ value ;
929
914
}
915
+ return $ value ;
930
916
}
931
917
932
918
public function boolToInt (bool $ bool ): int
933
919
{
934
- ($ bool ) ? $ int = 1 : $ int = 0 ;
935
- return $ int ;
920
+ return ($ bool ) ? 1 : 0 ;
936
921
}
937
922
938
923
public function saveOutput (string $ save_as , $ output )
0 commit comments