Completed
Pull Request — master (#46)
by
unknown
01:13
created

OVHConfiguration::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 9.472
c 0
b 0
f 0
cc 1
nc 1
nop 12

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace Sausin\LaravelOvh;
4
5
use BadMethodCallException;
6
7
class OVHConfiguration
8
{
9
    /** @var string */
10
    protected $authUrl;
11
12
    /** @var string */
13
    protected $projectId;
14
15
    /** @var string */
16
    protected $region;
17
18
    /** @var string */
19
    protected $userDomain;
20
21
    /** @var string */
22
    protected $username;
23
24
    /** @var string */
25
    protected $password;
26
27
    /** @var string */
28
    protected $container;
29
30
    /** @var string|null */
31
    private $tempUrlKey;
32
33
    /** @var string|null */
34
    private $endpoint;
35
36
    /** @var string|null */
37
    private $swiftLargeObjectThreshold;
38
39
    /** @var string|null */
40
    private $swiftSegmentSize;
41
42
    /** @var string|null */
43
    private $swiftSegmentContainer;
44
45
    /**
46
     * OVHConfiguration constructor.
47
     *
48
     * @param string $authUrl
49
     * @param string $projectId
50
     * @param string $region
51
     * @param string $userDomain
52
     * @param string $username
53
     * @param string $password
54
     * @param string $container
55
     * @param string|null $tempUrlKey
56
     * @param string|null $endpoint
57
     * @param string|null $swiftLargeObjectThreshold
58
     * @param string|null $swiftSegmentSize
59
     * @param string|null $swiftSegmentContainer
60
     */
61
    public function __construct(
62
        string $authUrl,
63
        string $projectId,
64
        string $region,
65
        string $userDomain,
66
        string $username,
67
        string $password,
68
        string $container,
69
        ?string $tempUrlKey,
70
        ?string $endpoint,
71
        ?string $swiftLargeObjectThreshold,
72
        ?string $swiftSegmentSize,
73
        ?string $swiftSegmentContainer
74
    )
75
    {
76
        $this->authUrl = $authUrl;
77
        $this->projectId = $projectId;
78
        $this->region = $region;
79
        $this->userDomain = $userDomain;
80
        $this->username = $username;
81
        $this->password = $password;
82
        $this->container = $container;
83
        $this->tempUrlKey = $tempUrlKey;
84
        $this->endpoint = $endpoint;
85
        $this->swiftLargeObjectThreshold = $swiftLargeObjectThreshold;
86
        $this->swiftSegmentSize = $swiftSegmentSize;
87
        $this->swiftSegmentContainer = $swiftSegmentContainer;
88
    }
89
90
    /**
91
     * Creates a new OVHConfiguration instance.
92
     *
93
     * @param array $config
94
     * @return static
95
     */
96
    public static function make(array $config): self
97
    {
98
        $neededKeys = ['authUrl', 'projectId', 'region', 'userDomain', 'username', 'password', 'container', 'tempUrlKey', 'endpoint'];
99
        $missingKeys = array_diff($neededKeys, array_keys($config));
100
101
        if (count($missingKeys) > 0) {
102
            throw new BadMethodCallException('The following keys must be provided: ' . implode(', ', $missingKeys));
103
        }
104
105
        return new self(
106
            $config['authUrl'],
107
            $config['projectId'],
108
            $config['region'],
109
            $config['userDomain'],
110
            $config['username'],
111
            $config['password'],
112
            $config['container'],
113
            $config['tempUrlKey'],
114
            $config['endpoint'],
115
            $config['swiftLargeObjectThreshold'] ?? null,
116
            $config['swiftSegmentSize'] ?? null,
117
            $config['swiftSegmentContainer'] ?? null
118
        );
119
    }
120
121
    /**
122
     * Returns the Project Auth Server URL.
123
     *
124
     * @return string
125
     */
126
    public function getAuthUrl(): string
127
    {
128
        return $this->authUrl;
129
    }
130
131
    /**
132
     * Returns the Project Id.
133
     *
134
     * @return string
135
     */
136
    public function getProjectId(): string
137
    {
138
        return $this->projectId;
139
    }
140
141
    /**
142
     * Returns the Project Region.
143
     * It could be one of the following:
144
     *  - BHS
145
     *  - DE
146
     *  - GRA
147
     *  - SBG
148
     *  - UK
149
     *  - WAW
150
     *
151
     * @return string
152
     */
153
    public function getRegion(): string
154
    {
155
        return $this->region;
156
    }
157
158
    /**
159
     * Returns the User Domain in the Project.
160
     * OVH uses the "Default" region by... default...
161
     *
162
     * @return string
163
     */
164
    public function getUserDomain(): string
165
    {
166
        return $this->userDomain;
167
    }
168
169
    /**
170
     * Returns the Project Username.
171
     *
172
     * @return string
173
     */
174
    public function getUsername(): string
175
    {
176
        return $this->username;
177
    }
178
179
    /**
180
     * Returns the Password for the current User.
181
     *
182
     * @return string
183
     */
184
    public function getPassword(): string
185
    {
186
        return $this->password;
187
    }
188
189
    /**
190
     * Returns the name of the desired Container.
191
     *
192
     * @return string
193
     */
194
    public function getContainer(): string
195
    {
196
        return $this->container;
197
    }
198
199
    /**
200
     * Returns the pre-assigned Temp Url Key of either the Container or Project.
201
     * This is used to generate Temporary Access Urls for files in the container.
202
     *
203
     * @return string|null
204
     */
205
    public function getTempUrlKey(): ?string
206
    {
207
        return $this->tempUrlKey;
208
    }
209
210
    /**
211
     * Returns the Custom Endpoint configured for the container.
212
     *
213
     * @return string|null
214
     */
215
    public function getEndpoint(): ?string
216
    {
217
        return $this->endpoint;
218
    }
219
220
    /**
221
     * Returns Object Threshold, used while uploading large files.
222
     *
223
     * @return string|null
224
     */
225
    public function getSwiftLargeObjectThreshold(): ?string
226
    {
227
        return $this->swiftLargeObjectThreshold;
228
    }
229
230
    /**
231
     * Returns Object Segment Size, used while uploading large files.
232
     *
233
     * @return string|null
234
     */
235
    public function getSwiftSegmentSize(): ?string
236
    {
237
        return $this->swiftSegmentSize;
238
    }
239
240
    /**
241
     * Returns Container Segment, used while uploading large files.
242
     *
243
     * @return string|null
244
     */
245
    public function getSwiftSegmentContainer(): ?string
246
    {
247
        return $this->swiftSegmentContainer;
248
    }
249
}