WebServiceGateway   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 96
Duplicated Lines 62.5 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 2
dl 60
loc 96
ccs 54
cts 54
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getServers() 11 11 2
A getServer() 11 11 2
A createServer() 0 19 2
A deleteServer() 11 11 2
A setAction() 16 16 2
A getUserData() 11 11 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace ChrisArmitage\ScalewayApi\WebService\Servers;
4
5
use ChrisArmitage\ScalewayApi\Client;
6
7
class WebServiceGateway
8
{
9
    /**
10
     * @var Client
11
     */
12
    protected $client;
13
14 12
    public function __construct(Client $client) {
15 12
        $this->client = $client;
16 12
    }
17
18 2 View Code Duplication
    public function getServers() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
        try {
20 2
            $this->client->setResource('servers')
21 2
                ->setMethod('GET');
22 2
            $response = $this->client->call();
23 2
        } catch (\Exception $e) {
24 1
            throw new GeneralException('GetServers call failed', 0, $e);
25
        }
26
27 1
        return json_decode($response);
28
    }
29
30 2 View Code Duplication
    public function getServer($serverId) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
        try {
32 2
            $this->client->setResource("servers/{$serverId}")
33 2
                ->setMethod('GET');
34 2
            $response = $this->client->call();
35 2
        } catch (\Exception $e) {
36 1
            throw new GeneralException('GetServer call failed', 0, $e);
37
        }
38
39 1
        return json_decode($response);
40
    }
41
42 2
    public function createServer($name, $organizationId, $imageId, $commercialType) {
43
        try {
44 2
            $this->client->setResource('servers')
45 2
                ->setMethod('POST')
46 2
                ->setParameters(
47
                    [
48 2
                        'name'            => $name,
49 2
                        'organization'    => $organizationId,
50 2
                        'image'           => $imageId,
51 2
                        'commercial_type' => $commercialType,
52
                    ]
53 2
                );
54 2
            $response = $this->client->call();
55 2
        } catch (\Exception $e) {
56 1
            throw new GeneralException('CreateServer call failed', 0, $e);
57
        }
58
59 1
        return json_decode($response);
60
    }
61
62 2 View Code Duplication
    public function deleteServer($serverId) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
        try {
64 2
            $this->client->setResource("servers/{$serverId}")
65 2
                ->setMethod('DELETE');
66 2
            $response = $this->client->call();
67 2
        } catch (\Exception $e) {
68 1
            throw new GeneralException('DeleteServer call failed', 0, $e);
69
        }
70
71 1
        return json_decode($response);
72
    }
73
74 2 View Code Duplication
    public function setAction($serverId, $action) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
        try {
76 2
            $this->client->setResource("servers/{$serverId}/action")
77 2
                ->setMethod('POST')
78 2
                ->setParameters(
79
                    [
80
                        'action' => $action
81 2
                    ]
82 2
                );
83 2
            $response = $this->client->call();
84 2
        } catch (\Exception $e) {
85 1
            throw new GeneralException('SetAction call failed', 0, $e);
86
        }
87
88 1
        return json_decode($response);
89
    }
90
91 2 View Code Duplication
    public function getUserData($serverId, $key) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
92
        try {
93 2
            $this->client->setResource("servers/{$serverId}/user_data/{$key}")
94 2
                ->setMethod('GET');
95 2
            $response = $this->client->call();
96 2
        } catch (\Exception $e) {
97 1
            throw new GeneralException('GetUserData call failed', 0, $e);
98
        }
99
100 1
        return $response;
101
    }
102
}
103