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

Container::UpdateChanges()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 0
cts 3
cp 0
crap 2
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
}