Passed
Push — master ( 8027e2...2ce077 )
by Bence
01:59
created

Container   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 47
ccs 0
cts 33
cp 0
rs 10
c 0
b 0
f 0
wmc 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A UpdateStatus() 0 3 1
A __construct() 0 4 1
A SetConfiguration() 0 2 1
A GetContainerName() 0 2 1
A IsRunning() 0 2 1
A GetLastLogId() 0 2 1
A GetId() 0 2 1
A GetConfiguration() 0 2 1
A SetContainerName() 0 2 1
A UpdateChanges() 0 3 1
1
<?php
2
3
namespace CSFCloud\Containers;
4
5
use CSFCloud\KeyManager;
6
use CSFCloud\Resource;
7
use Httpful\Request;
8
9
class Container extends Resource {
10
11
    private $containerId;
12
    private $statusCache;
13
14
    public function __construct(KeyManager $km, string $id) {
15
        parent::__construct($km);
16
        $this->containerId = $id;
17
        $this->UpdateStatus();
18
    }
19
20
    private function UpdateStatus() {
21
        $request = Request::get("https://api.csfcloud.com/container/" . urlencode($this->containerId) . "?key=" . urlencode($this->keymanager->GetServerKey()))->expectsText()->send();
22
        $this->statusCache = json_decode($request->body, true);
23
    }
24
25
    public function GetId() : string {
26
        return $this->containerId;
27
    }
28
29
    public function GetConfiguration() : array {
30
        return $this->statusCache["configuration"];
31
    }
32
33
    public function SetConfiguration(array $cnf) {
34
        $this->statusCache["configuration"] = $cnf;
35
    }
36
37
    public function UpdateChanges() {
38
        Request::put("https://api.csfcloud.com/container/" . urlencode($this->containerId) . "?key=" . urlencode($this->keymanager->GetServerKey()))
39
            ->sendsJson()->body(json_encode($this->statusCache["configuration"]))->send();
40
    }
41
42
    public function GetContainerName() : string {
43
        return $this->statusCache["configuration"]["name"];
44
    }
45
46
    public function SetContainerName(string $newname) {
47
        $this->statusCache["configuration"]["name"] = $newname;
48
    }
49
50
    public function IsRunning() : bool {
51
        return $this->statusCache["running"];
52
    }
53
54
    public function GetLastLogId() : ?string {
55
        return $this->statusCache["last_log"];
56
    }
57
58
}