Passed
Push — master ( b5dd62...a52853 )
by Jared
02:11
created

ConfigForm::addAzure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 52
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 37
nc 1
nop 0
dl 0
loc 52
rs 9.328
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace AnyCloud\Form;
4
5
use Zend\Form\Form;
1 ignored issue
show
Bug introduced by
The type Zend\Form\Form was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Zend\Form\Element;
1 ignored issue
show
Bug introduced by
The type Zend\Form\Element was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Zend\Form\Fieldset;
1 ignored issue
show
Bug introduced by
The type Zend\Form\Fieldset was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
class ConfigForm extends Form
10
{
11
    protected $settings;
12
13
    public function setSettings($settings)
14
    {
15
        $this->settings = $settings;
16
    }
17
18
    public function init()
19
    {
20
        $this->addCsrf();
21
        $this->addAdapter();
22
        $this->addAws();
23
        $this->addAzure();
24
        $this->addGoogle();
25
        $this->addDigitalOcean();
26
        $this->addScaleway();
27
        $this->addRackspace();
28
        $this->addDropbox();
29
    }
30
31
    protected function getSetting($name)
32
    {
33
        return $this->settings->get($name);
34
    }
35
36
    private function addCsrf()
37
    {
38
        $this->add([
39
            'type' => Element\Csrf::class,
0 ignored issues
show
Bug introduced by
The type Zend\Form\Element\Csrf was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
40
            'name' => 'csrf',
41
            'options' => [
42
                'csrf_options' => [
43
                    'timeout' => 600,
44
                ],
45
            ],
46
        ]);
47
    }
48
49
    private function addAdapter()
50
    {
51
        $this->add([
52
            'name' => 'anycloud_adapter',
53
            'type' => Fieldset::class,
54
            'options' => [
55
                'label' => 'Any Cloud Adapter',
56
            ],
57
            'attributes' => [
58
                'id' => 'adapter-fieldset',
59
            ],
60
        ]);
61
        $adapterFieldset = $this->get('anycloud_adapter');
62
        $adapterFieldset->add([
63
            'name' => 'adapter',
64
            'type' => Element\Select::class,
1 ignored issue
show
Bug introduced by
The type Zend\Form\Element\Select was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
65
            'options' => [
66
                'label' => 'Cloud Service Adapter: ',
67
                'value_options' => [
68
                    'default' => 'Omeka Default (local server)',
69
                    'aws' => 'Amazon S3 Storage',
70
                    'azure' => 'Microsoft Azure Storage',
71
                    'google' => 'Google Cloud Storage',
72
                    'digital_ocean' => 'DigitalOcean Spaces',
73
                    'scaleway' => 'Scaleway Object Storage',
74
                    'rackspace' => 'Rackspace Files',
75
                    'dropbox' => 'Dropbox',
76
                ],
77
            ],
78
            'attributes' => [
79
                'id' => 'adapter',
80
            ],
81
        ]);
82
    }
83
84
    private function addAws()
85
    {
86
        $this->add([
87
            'name' => 'anycloud_aws',
88
            'type' => Fieldset::class,
89
            'options' => [
90
                'label' => 'AmazonS3 Storage',
91
            ],
92
            'attributes' => [
93
                'class' => 'aws fieldset',
94
            ],
95
        ]);
96
        $awsFieldset = $this->get('anycloud_aws');
97
        $awsFieldset->add([
98
            'name' => 'aws_key',
99
            'type' => Element\Text::class,
1 ignored issue
show
Bug introduced by
The type Zend\Form\Element\Text was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
100
            'options' => [
101
                'label' => 'AWS Key',
102
            ],
103
            'attributes' => [
104
                'id' => 'aws_key',
105
            ],
106
        ]);
107
        $awsFieldset->add([
108
            'name' => 'aws_secret_key',
109
            'type' => Element\Text::class,
110
            'options' => [
111
                'label' => 'AWS Secret Key',
112
            ],
113
            'attributes' => [
114
                'id' => 'aws_secret_key',
115
                'cols' => '100',
116
            ],
117
        ]);
118
        $awsFieldset->add([
119
            'name' => 'aws_bucket',
120
            'type' => Element\Text::class,
121
            'options' => [
122
                'label' => 'AWS Bucket',
123
            ],
124
            'attributes' => [
125
                'id' => 'aws_bucket',
126
            ],
127
        ]);
128
        $awsFieldset->add([
129
            'name' => 'aws_region',
130
            'type' => Element\Text::class,
131
            'options' => [
132
                'label' => 'AWS Region',
133
            ],
134
            'attributes' => [
135
                'id' => 'aws_region',
136
            ],
137
        ]);
138
        $awsFieldset->add([
139
            'name' => 'aws_endpoint',
140
            'type' => Element\Text::class,
141
            'options' => [
142
                'label' => 'AWS Endpoint',
143
                'info' => 'Can usually leave blank unless you have a custom endpoint set up. See https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region',
144
            ],
145
            'attributes' => [
146
                'id' => 'aws_endpoint',
147
            ],
148
        ]);
149
    }
150
151
    private function addAzure()
152
    {
153
        $this->add([
154
            'name' => 'anycloud_azure',
155
            'type' => Fieldset::class,
156
            'options' => [
157
                'label' => 'Microsoft Azure Storage',
158
            ],
159
            'attributes' => [
160
                'class' => 'azure fieldset',
161
            ],
162
        ]);
163
        $azureFieldset = $this->get('anycloud_azure');
164
        $azureFieldset->add([
165
            'name' => 'azure_account_name',
166
            'type' => Element\Text::class,
167
            'options' => [
168
                'label' => 'Azure Account Name',
169
            ],
170
            'attributes' => [
171
                'id' => 'azure_account_name',
172
            ],
173
        ]);
174
        $azureFieldset->add([
175
            'name' => 'azure_account_key',
176
            'type' => Element\Text::class,
177
            'options' => [
178
                'label' => 'Azure Account Key',
179
            ],
180
            'attributes' => [
181
                'id' => 'azure_account_key',
182
            ],
183
        ]);
184
        $azureFieldset->add([
185
            'name' => 'azure_container_name',
186
            'type' => Element\Text::class,
187
            'options' => [
188
                'label' => 'Azure Container Name',
189
            ],
190
            'attributes' => [
191
                'id' => 'azure_container_name',
192
            ],
193
        ]);
194
        $azureFieldset->add([
195
            'name' => 'azure_endpoint',
196
            'type' => Element\Text::class,
197
            'options' => [
198
                'label' => 'Azure Endpoint',
199
                'info' => 'Can usually leave blank unless you have a custom endpoint set up',
200
            ],
201
            'attributes' => [
202
                'id' => 'azure_endpoint',
203
            ],
204
        ]);
205
    }
206
207
    private function addGoogle()
208
    {
209
        $this->add([
210
            'name' => 'anycloud_google',
211
            'type' => Fieldset::class,
212
            'options' => [
213
                'label' => 'Google Cloud Storage',
214
            ],
215
            'attributes' => [
216
                'class' => 'google fieldset',
217
            ],
218
        ]);
219
        $googleFieldset = $this->get('anycloud_google');
220
        $googleFieldset->add([
221
            'name' => 'google_project_id',
222
            'type' => Element\Text::class,
223
            'options' => [
224
                'label' => 'Google Project ID',
225
            ],
226
            'attributes' => [
227
                'id' => 'google_project_id',
228
            ],
229
        ]);
230
        $googleFieldset->add([
231
            'name' => 'google_bucket_name',
232
            'type' => Element\Text::class,
233
            'options' => [
234
                'label' => 'Google Bucket Name',
235
            ],
236
            'attributes' => [
237
                'id' => 'google_bucket_name',
238
            ],
239
        ]);
240
        $googleFieldset->add([
241
            'name' => 'google_credentials_path',
242
            'type' => Element\Text::class,
243
            'options' => [
244
                'label' => 'Google Credentials Path',
245
                'info' => 'Replace {CONFIG} with the name of your Google credentials file stored at the listed path',
246
                'value' => '/src/Service/File/Adapter/Google/{CONFIG}.json',
247
            ],
248
            'attributes' => [
249
                'id' => 'google_credentials_path',
250
            ],
251
        ]);
252
        $googleFieldset->add([
253
            'name' => 'google_storage_uri',
254
            'type' => Element\Text::class,
255
            'options' => [
256
                'label' => 'Google Storage URI',
257
                'info' => 'You can usually leave this as the default unless you have tweaked other settings',
258
                'value' => 'https://storage.googleapis.com',
259
            ],
260
            'attributes' => [
261
                'id' => 'google_storage_uri',
262
            ],
263
        ]);
264
    }
265
266
    private function addDigitalOcean()
267
    {
268
        $this->add([
269
            'name' => 'anycloud_digital_ocean',
270
            'type' => Fieldset::class,
271
            'options' => [
272
                'label' => 'DigitalOcean Spaces',
273
            ],
274
            'attributes' => [
275
                'class' => 'digital_ocean fieldset',
276
            ],
277
        ]);
278
        $digitaloceanFieldset = $this->get('anycloud_digital_ocean');
279
        $digitaloceanFieldset->add([
280
            'name' => 'digital_ocean_key',
281
            'type' => Element\Text::class,
282
            'options' => [
283
                'label' => 'DigitalOcean AWS Key',
284
            ],
285
            'attributes' => [
286
                'id' => 'digital_ocean_key',
287
            ],
288
        ]);
289
        $digitaloceanFieldset->add([
290
            'name' => 'digital_ocean_secret_key',
291
            'type' => Element\Text::class,
292
            'options' => [
293
                'label' => 'DigitalOcean AWS Secret Key',
294
            ],
295
            'attributes' => [
296
                'id' => 'digital_ocean_secret_key',
297
            ],
298
        ]);
299
        $digitaloceanFieldset->add([
300
            'name' => 'digital_ocean_bucket',
301
            'type' => Element\Text::class,
302
            'options' => [
303
                'label' => 'DigitalOcean AWS Bucket',
304
            ],
305
            'attributes' => [
306
                'id' => 'digital_ocean_bucket',
307
            ],
308
        ]);
309
        $digitaloceanFieldset->add([
310
            'name' => 'digital_ocean_region',
311
            'type' => Element\Text::class,
312
            'options' => [
313
                'label' => 'DigitalOcean AWS Region',
314
            ],
315
            'attributes' => [
316
                'id' => 'digital_ocean_region',
317
            ],
318
        ]);
319
        $digitaloceanFieldset->add([
320
            'name' => 'digital_ocean_endpoint',
321
            'type' => Element\Text::class,
322
            'options' => [
323
                'label' => 'DigitalOcean AWS Endpoint',
324
            ],
325
            'attributes' => [
326
                'id' => 'digital_ocean_endpoint',
327
            ],
328
        ]);
329
    }
330
331
    private function addScaleway()
332
    {
333
        $this->add([
334
            'name' => 'anycloud_scaleway',
335
            'type' => Fieldset::class,
336
            'options' => [
337
                'label' => 'Scaleway Object Storage',
338
            ],
339
            'attributes' => [
340
                'class' => 'scaleway fieldset',
341
            ],
342
        ]);
343
        $scalewayFieldset = $this->get('anycloud_scaleway');
344
        $scalewayFieldset->add([
345
            'name' => 'scaleway_key',
346
            'type' => Element\Text::class,
347
            'options' => [
348
                'label' => 'Scaleway AWS Key',
349
            ],
350
            'attributes' => [
351
                'id' => 'scaleway_key',
352
            ],
353
        ]);
354
        $scalewayFieldset->add([
355
            'name' => 'scaleway_secret_key',
356
            'type' => Element\Text::class,
357
            'options' => [
358
                'label' => 'Scaleway AWS Secret Key',
359
            ],
360
            'attributes' => [
361
                'id' => 'scaleway_secret_key',
362
            ],
363
        ]);
364
        $scalewayFieldset->add([
365
            'name' => 'scaleway_bucket',
366
            'type' => Element\Text::class,
367
            'options' => [
368
                'label' => 'Scaleway AWS Bucket',
369
            ],
370
            'attributes' => [
371
                'id' => 'scaleway_bucket',
372
            ],
373
        ]);
374
        $scalewayFieldset->add([
375
            'name' => 'scaleway_region',
376
            'type' => Element\Text::class,
377
            'options' => [
378
                'label' => 'Scaleway AWS Region',
379
            ],
380
            'attributes' => [
381
                'id' => 'scaleway_region',
382
            ],
383
        ]);
384
        $scalewayFieldset->add([
385
            'name' => 'scaleway_endpoint',
386
            'type' => Element\Text::class,
387
            'options' => [
388
                'label' => 'Scaleway AWS Endpoint',
389
            ],
390
            'attributes' => [
391
                'id' => 'scaleway_endpoint',
392
            ],
393
        ]);
394
    }
395
396
    private function addRackspace()
397
    {
398
        $this->add([
399
            'name' => 'anycloud_rackspace',
400
            'type' => Fieldset::class,
401
            'options' => [
402
                'label' => 'Rackspace Files',
403
            ],
404
            'attributes' => [
405
                'class' => 'rackspace fieldset',
406
            ],
407
        ]);
408
        $rackspaceFieldset = $this->get('anycloud_rackspace');
409
        $rackspaceFieldset->add([
410
            'name' => 'rackspace_identity_endpoint',
411
            'type' => Element\Text::class,
412
            'options' => [
413
                'label' => 'Rackspace Identity Endpoint',
414
                'info' => 'Valid options include “US_IDENTITY_ENDPOINT” and “UK_IDENTITY_ENDPOINT”',
415
            ],
416
            'attributes' => [
417
                'id' => 'rackspace_identity_endpoint',
418
            ],
419
        ]);
420
        $rackspaceFieldset->add([
421
            'name' => 'rackspace_username',
422
            'type' => Element\Text::class,
423
            'options' => [
424
                'label' => 'Rackspace Username',
425
            ],
426
            'attributes' => [
427
                'id' => 'rackspace_username',
428
            ],
429
        ]);
430
        $rackspaceFieldset->add([
431
            'name' => 'rackspace_password',
432
            'type' => Element\Text::class,
433
            'options' => [
434
                'label' => 'Rackspace Password',
435
            ],
436
            'attributes' => [
437
                'id' => 'rackspace_password',
438
            ],
439
        ]);
440
        $rackspaceFieldset->add([
441
            'name' => 'rackspace_container',
442
            'type' => Element\Text::class,
443
            'options' => [
444
                'label' => 'Rackspace Container Name',
445
            ],
446
            'attributes' => [
447
                'id' => 'rackspace_container',
448
            ],
449
        ]);
450
        $rackspaceFieldset->add([
451
            'name' => 'rackspace_region',
452
            'type' => Element\Text::class,
453
            'options' => [
454
                'label' => 'Rackspace Region',
455
            ],
456
            'attributes' => [
457
                'id' => 'rackspace_region',
458
            ],
459
        ]);
460
    }
461
462
    private function addDropbox()
463
    {
464
        $this->add([
465
            'name' => 'anycloud_dropbox',
466
            'type' => Fieldset::class,
467
            'options' => [
468
                'label' => 'Dropbox',
469
            ],
470
            'attributes' => [
471
                'class' => 'dropbox fieldset',
472
            ],
473
        ]);
474
        $dropboxFieldset = $this->get('anycloud_dropbox');
475
        $dropboxFieldset->add([
476
            'name' => 'dropbox_access_token',
477
            'type' => Element\Text::class,
478
            'options' => [
479
                'label' => 'Dropbox Access Token',
480
            ],
481
            'attributes' => [
482
                'id' => 'dropbox_access_token',
483
            ],
484
        ]);
485
    }
486
}
487