Completed
Push — master ( 2e7ae5...1f4f02 )
by Timur
02:34
created

Site   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 86
rs 10
c 0
b 0
f 0

7 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 install() 0 8 1
A uninstall() 0 6 1
A balance() 0 8 1
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
     * Install new application on site.
52
     *
53
     * @param \Laravel\Forge\Contracts\ApplicationContract $application
54
     *
55
     * @return bool
56
     */
57
    public function install(ApplicationContract $application)
58
    {
59
        $this->getHttpClient()->request('POST', $this->apiUrl($application->type()), [
60
            'json' => $application->payload(),
61
        ]);
62
63
        return true;
64
    }
65
66
    /**
67
     * Uninstall application from site.
68
     *
69
     * @param \Laravel\Forge\Contracts\ApplicationContract $application
70
     *
71
     * @return bool
72
     */
73
    public function uninstall(ApplicationContract $application)
74
    {
75
        $this->getHttpClient()->request('DELETE', $this->apiUrl($application->type()));
76
77
        return true;
78
    }
79
80
    /**
81
     * Connect load balancer.
82
     *
83
     * @return bool
84
     */
85
    public function balance(array $serverIds)
86
    {
87
        $this->getHttpClient()->request('PUT', $this->apiUrl('/balancing'), [
88
            'json' => ['servers' => $serverIds]
89
        ]);
90
91
        return true;
92
    }
93
}
94