Test Setup Failed
Push — master ( 84d668...ef9790 )
by Sergio
03:52
created

HetznerCloud::setClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: sergio.rodenas
5
 * Date: 29/7/18
6
 * Time: 18:43
7
 */
8
9
namespace Whisper\HetznerCloud\Clients;
10
11
use Zttp\PendingZttpRequest;
12
13
class HetznerCloud
14
{
15
	public static $baseHost = "https://api.hetzner.cloud/v1/";
16
	public static $authenticationToken;
17
18
	private static $client;
19
20
	public static function __callStatic($name, $arguments)
21
	{
22
		return (new static())->getClient()->{$name}(...$arguments)->json();
23
	}
24
25
	private function getClient(){
26
		return (static::$client) ? static::$client : static::setClient();
0 ignored issues
show
Bug introduced by
Since $client is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $client to at least protected.
Loading history...
Bug Best Practice introduced by
The method Whisper\HetznerCloud\Cli...tznerCloud::setClient() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
		return (static::$client) ? static::$client : static::/** @scrutinizer ignore-call */ setClient();
Loading history...
27
	}
28
29
	private function setClient(){
30
		$client = (new PendingZttpRequest())->withHeaders([
31
			'Authorization' => 'Bearer '.static::$authenticationToken
32
		]);
33
34
		$client->options += [
35
			'base_uri' => static::$baseHost
36
		];
37
38
		return static::$client = $client;
0 ignored issues
show
Bug introduced by
Since $client is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $client to at least protected.
Loading history...
39
	}
40
}