Completed
Push — master ( 3cc9b0...d35865 )
by Timur
02:56
created

Certificate::install()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
1
<?php
2
3
namespace Laravel\Forge\Certificates;
4
5
use Laravel\Forge\ApiResource;
6
7
class Certificate extends ApiResource
8
{
9
    /**
10
     * Resource type.
11
     *
12
     * @return string
13
     */
14
    public static function resourceType()
15
    {
16
        return 'certificate';
17
    }
18
19
    /**
20
     * Resource path (relative to owner or API root).
21
     *
22
     * @return string
23
     */
24
    public function resourcePath()
25
    {
26
        return 'certificates';
27
    }
28
29
    /**
30
     * Resource name.
31
     *
32
     * @return string|null
33
     */
34
    public function name()
35
    {
36
        return $this->domain();
37
    }
38
39
    /**
40
     * Certificate domain.
41
     *
42
     * @return string|null
43
     */
44
    public function domain()
45
    {
46
        return $this->getData('domain');
47
    }
48
49
    /**
50
     * Certificate type.
51
     *
52
     * @return string|null
53
     */
54
    public function type()
55
    {
56
        return $this->getData('type');
57
    }
58
59
    /**
60
     * Request status.
61
     *
62
     * @return string|null
63
     */
64
    public function requestStatus()
65
    {
66
        return $this->getData('request_status');
67
    }
68
69
    /**
70
     * Determines if certificate is active.
71
     *
72
     * @return bool
73
     */
74
    public function active(): bool
75
    {
76
        return intval($this->getData('active')) === 1;
77
    }
78
79
    /**
80
     * Determines if current certificate was installed from existing certificate.
81
     *
82
     * @return bool
83
     */
84
    public function existing(): bool
85
    {
86
        return intval($this->getData('existing')) === 1;
87
    }
88
89
    /**
90
     * Determines if current certificate is Let's Encrypt certificate.
91
     *
92
     * @return bool
93
     */
94
    public function letsencrypt(): bool
95
    {
96
        return $this->type() === 'letsencrypt';
97
    }
98
99
    /**
100
     * Get Certificate Signing Request value.
101
     *
102
     * @return string
103
     */
104
    public function csr()
105
    {
106
        $response = $this->getHttpClient()->request('GET', $this->apiUrl('/csr'));
107
108
        return (string) $response->getBody();
109
    }
110
111
    /**
112
     * Install certificate.
113
     *
114
     * @param string $content
115
     * @param bool   $addIntermediates = false
116
     *
117
     * @return string|null
118
     */
119
    public function install(string $content, bool $addIntermediates = false): bool
120
    {
121
        $response = $this->getHttpClient()->request('POST', $this->apiUrl('/install'), [
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
122
            'form_params' => [
123
                'certificate' => $content,
124
                'add_intermediates' => $addIntermediates,
125
            ],
126
        ]);
127
128
        return true;
129
    }
130
131
    /**
132
     * Activate certificate.
133
     *
134
     * @return bool
135
     */
136
    public function activate(): bool
137
    {
138
        $this->getHttpClient()->request('POST', $this->apiUrl('/activate'));
139
140
        return true;
141
    }
142
}
143