Completed
Push — master ( 14b89e...4d034c )
by Timur
07:23 queued 02:10
created

Site   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 222
Duplicated Lines 7.21 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
wmc 20
lcom 2
cbo 3
dl 16
loc 222
rs 10
c 0
b 0
f 0

20 Methods

Rating   Name   Duplication   Size   Complexity  
A resourceType() 0 4 1
A resourcePath() 0 4 1
A domain() 0 4 1
A projectType() 0 4 1
A directory() 0 4 1
A repository() 0 4 1
A repositoryProvider() 0 4 1
A repositoryBranch() 0 4 1
A repositoryStatus() 0 4 1
A deploymentStatus() 0 4 1
A wildcards() 0 4 1
A quickDeploy() 0 4 1
A hipchatRoom() 0 4 1
A slackChannel() 0 4 1
A app() 0 4 1
A appStatus() 0 4 1
A install() 8 8 1
A updateApplication() 8 8 1
A uninstall() 0 6 1
A balance() 0 8 1

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 Laravel\Forge\Sites;
4
5
use Laravel\Forge\Contracts\ApplicationContract;
6
use Laravel\Forge\ApiResource;
7
8
class Site extends ApiResource
9
{
10
    /**
11
     * Resource type.
12
     *
13
     * @return string
14
     */
15
    public static function resourceType()
16
    {
17
        return 'site';
18
    }
19
20
    /**
21
     * Resource path (relative to Server URL).
22
     *
23
     * @return string
24
     */
25
    public function resourcePath()
26
    {
27
        return 'sites';
28
    }
29
30
    /**
31
     * Site domain.
32
     *
33
     * @return string
34
     */
35
    public function domain()
36
    {
37
        return $this->getData('name');
38
    }
39
40
    /**
41
     * Project type.
42
     *
43
     * @return string
44
     */
45
    public function projectType()
46
    {
47
        return $this->getData('project_type');
48
    }
49
50
    /**
51
     * Site directory.
52
     *
53
     * @return string
54
     */
55
    public function directory()
56
    {
57
        return $this->getData('directory');
58
    }
59
60
    /**
61
     * Site repository.
62
     *
63
     * @return string
64
     */
65
    public function repository()
66
    {
67
        return $this->getData('repository');
68
    }
69
70
    /**
71
     * Site repository provider.
72
     *
73
     * @return string
74
     */
75
    public function repositoryProvider()
76
    {
77
        return $this->getData('repository_provider');
78
    }
79
80
    /**
81
     * Site repository branch.
82
     *
83
     * @return string
84
     */
85
    public function repositoryBranch()
86
    {
87
        return $this->getData('repository_branch');
88
    }
89
90
    /**
91
     * Site repository status.
92
     *
93
     * @return string
94
     */
95
    public function repositoryStatus()
96
    {
97
        return $this->getData('repository_status');
98
    }
99
100
    /**
101
     * Site deployment status.
102
     *
103
     * @return string | null
104
     */
105
    public function deploymentStatus()
106
    {
107
        return $this->getData('deployment_status');
108
    }
109
110
    /**
111
     * Site allows wildcard URIs.
112
     *
113
     * @return boolean
114
     */
115
    public function wildcards()
116
    {
117
        return $this->getData('wildcards');
118
    }
119
120
    /**
121
     * Site quick deploy enabled.
122
     *
123
     * @return boolean
124
     */
125
    public function quickDeploy()
126
    {
127
        return $this->getData('quick_deploy');
128
    }
129
130
    /**
131
     * Site hipchat room.
132
     *
133
     * @return string
134
     */
135
    public function hipchatRoom()
136
    {
137
        return $this->getData('hipchat_room');
138
    }
139
140
    /**
141
     * Site slack channel.
142
     *
143
     * @return string
144
     */
145
    public function slackChannel()
146
    {
147
        return $this->getData('slack_channel');
148
    }
149
150
    /**
151
     * Site app.
152
     *
153
     * @return string | null
154
     */
155
    public function app()
156
    {
157
        return $this->getData('app');
158
    }
159
160
    /**
161
     * Site app status.
162
     *
163
     * @return string | null
164
     */
165
    public function appStatus()
166
    {
167
        return $this->getData('app_status');
168
    }
169
170
    /**
171
     * Install new application on site.
172
     *
173
     * @param \Laravel\Forge\Contracts\ApplicationContract $application
174
     *
175
     * @return bool
176
     */
177 View Code Duplication
    public function install(ApplicationContract $application)
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...
178
    {
179
        $this->getHttpClient()->request('POST', $this->apiUrl($application->type()), [
180
            'json' => $application->payload(),
181
        ]);
182
183
        return true;
184
    }
185
186
    /**
187
     * Install new application on site.
188
     *
189
     * @param \Laravel\Forge\Contracts\ApplicationContract $application
190
     *
191
     * @return bool
192
     */
193 View Code Duplication
    public function updateApplication(ApplicationContract $application)
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...
194
    {
195
        $this->getHttpClient()->request('PUT', $this->apiUrl($application->type()), [
196
            'json' => $application->payload(),
197
        ]);
198
199
        return true;
200
    }
201
202
    /**
203
     * Uninstall application from site.
204
     *
205
     * @param \Laravel\Forge\Contracts\ApplicationContract $application
206
     *
207
     * @return bool
208
     */
209
    public function uninstall(ApplicationContract $application)
210
    {
211
        $this->getHttpClient()->request('DELETE', $this->apiUrl($application->type()));
212
213
        return true;
214
    }
215
216
    /**
217
     * Connect load balancer.
218
     *
219
     * @return bool
220
     */
221
    public function balance(array $serverIds)
222
    {
223
        $this->getHttpClient()->request('PUT', $this->apiUrl('/balancing'), [
224
            'json' => ['servers' => $serverIds]
225
        ]);
226
227
        return true;
228
    }
229
}
230