Completed
Push — master ( 8d2e1a...342cfd )
by Chris
06:03
created

Servers::getAllServers()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 0
crap 2
1
<?php
2
3
namespace ChrisArmitage\ScalewayApi\Endpoint;
4
5
use ChrisArmitage\ScalewayApi\Client;
6
use ChrisArmitage\ScalewayApi\Domain\Server;
7
use ChrisArmitage\ScalewayApi\Domain\Task;
8
use ChrisArmitage\ScalewayApi\WebService\Servers\WebServiceGateway;
9
10
class Servers
11
{
12
    /**
13
     * @var Client
14
     */
15
    protected $client;
16
17
    /**
18
     * @var WebServiceGateway
19
     */
20
    protected $gateway;
21
22
    /**
23
     * @param WebServiceGateway $gateway
24
     */
25 4
    public function __construct(WebServiceGateway $gateway) {
26 4
        $this->gateway = $gateway;
27 4
    }
28
29
    /**
30
     * @return Server[]
31
     * @throws \Exception
32
     */
33 1
    public function getAllServers() {
34 1
        $response = $this->gateway->getServers();
35
36 1
        $collection = [];
37
38 1
        foreach ($response->servers as $server) {
39 1
            $collection[] = Server::makeFromServerJson($server);
40 1
        }
41
42 1
        return $collection;
43
    }
44
45
    /**
46
     * @param $serverId
47
     * @return Server
48
     * @throws \Exception
49
     */
50 1
    public function getServer($serverId) {
51 1
        $response = $this->gateway->getServer($serverId);
52
        
53 1
        return Server::makeFromServerJson($response->server);
54
    }
55
56
    /**
57
     * @param $name
58
     * @param $organizationId
59
     * @param $imageId
60
     * @param $commercialType
61
     * @return Server
62
     * @throws \Exception
63
     */
64 1
    public function createServer($name, $organizationId, $imageId, $commercialType) {
65 1
        $response = $this->gateway->createServer($name, $organizationId, $imageId, $commercialType);
66
67 1
        return Server::makeFromServerJson($response->server);
68
    }
69
70
    /**
71
     * @param $serverId
72
     * @return mixed
73
     * @throws \Exception
74
     */
75
    public function deleteServer($serverId) {
76
        $response = $this->gateway->deleteServer($serverId);
77
78
        return $response;
79
    }
80
81
    /**
82
     * @param $serverId
83
     * @param $action
84
     * @return Task
85
     * @throws \Exception
86
     */
87 1
    public function setAction($serverId, $action) {
88 1
        $response = $this->gateway->setAction($serverId, $action);
89
90 1
        return Task::makeFromTaskJson($response->task);
91
    }
92
}
93