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

OVHConfiguration::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 9.488
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
        $this->authUrl = $authUrl;
76
        $this->projectId = $projectId;
77
        $this->region = $region;
78
        $this->userDomain = $userDomain;
79
        $this->username = $username;
80
        $this->password = $password;
81
        $this->container = $container;
82
        $this->tempUrlKey = $tempUrlKey;
83
        $this->endpoint = $endpoint;
84
        $this->swiftLargeObjectThreshold = $swiftLargeObjectThreshold;
85
        $this->swiftSegmentSize = $swiftSegmentSize;
86
        $this->swiftSegmentContainer = $swiftSegmentContainer;
87
    }
88
89
    /**
90
     * Creates a new OVHConfiguration instance.
91
     *
92
     * @param array $config
93
     * @return static
94
     */
95
    public static function make(array $config): self
96
    {
97
        $neededKeys = ['authUrl', 'projectId', 'region', 'userDomain', 'username', 'password', 'container', 'tempUrlKey', 'endpoint'];
98
        $missingKeys = array_diff($neededKeys, array_keys($config));
99
100
        if (count($missingKeys) > 0) {
101
            throw new BadMethodCallException('The following keys must be provided: '.implode(', ', $missingKeys));
102
        }
103
104
        return new self(
105
            $config['authUrl'],
106
            $config['projectId'],
107
            $config['region'],
108
            $config['userDomain'],
109
            $config['username'],
110
            $config['password'],
111
            $config['container'],
112
            $config['tempUrlKey'],
113
            $config['endpoint'],
114
            $config['swiftLargeObjectThreshold'] ?? null,
115
            $config['swiftSegmentSize'] ?? null,
116
            $config['swiftSegmentContainer'] ?? null
117
        );
118
    }
119
120
    /**
121
     * Returns the Project Auth Server URL.
122
     *
123
     * @return string
124
     */
125
    public function getAuthUrl(): string
126
    {
127
        return $this->authUrl;
128
    }
129
130
    /**
131
     * Returns the Project Id.
132
     *
133
     * @return string
134
     */
135
    public function getProjectId(): string
136
    {
137
        return $this->projectId;
138
    }
139
140
    /**
141
     * Returns the Project Region.
142
     * It could be one of the following:
143
     *  - BHS
144
     *  - DE
145
     *  - GRA
146
     *  - SBG
147
     *  - UK
148
     *  - WAW
149
     * Make sure to check your container's region at OVH's Dashboard.
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
}