Completed
Push — master ( a0e8ce...60fa13 )
by Bas
12s
created

AwsS3AdapterFactory::validateConfig()   C

Complexity

Conditions 7
Paths 8

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 14
cts 14
cp 1
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 13
nc 8
nop 0
crap 7
1
<?php
2
3
namespace BsbFlysystem\Adapter\Factory;
4
5
use Aws\S3\S3Client;
6
use BsbFlysystem\Exception\RequirementsException;
7
use BsbFlysystem\Exception\UnexpectedValueException;
8
use League\Flysystem\AwsS3v2\AwsS3Adapter as Adapter;
9
use Zend\ServiceManager\ServiceLocatorInterface;
10
11
class AwsS3AdapterFactory extends AbstractAdapterFactory
12
{
13
14
    /**
15
     * @inheritdoc
16
     */
17
    public function doCreateService(ServiceLocatorInterface $serviceLocator)
18
    {
19
        if (!class_exists(\League\Flysystem\AwsS3v2\AwsS3Adapter::class)) {
20
            throw new RequirementsException(
21
                ['league/flysystem-aws-s3-v2'],
22
                'AwsS3'
23
            );
24
        }
25
26
        $client = S3Client::factory([
0 ignored issues
show
Deprecated Code introduced by
The method Aws\AwsClient::factory() has been deprecated.

This method has been deprecated.

Loading history...
27
            'key'    => $this->options['key'],
28
            'secret' => $this->options['secret'],
29
            'region' => $this->options['region'],
30
            'request.options' => $this->options['request.options'],
31
        ]);
32
33
        $adapter = new Adapter($client, $this->options['bucket'], $this->options['prefix']);
34
35
        return $adapter;
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41 5
    protected function validateConfig()
42
    {
43 5
        if (!isset($this->options['key'])) {
44 1
            throw new UnexpectedValueException("Missing 'key' as option");
45
        }
46
47 4
        if (!isset($this->options['secret'])) {
48 1
            throw new UnexpectedValueException("Missing 'secret' as option");
49
        }
50
51 3
        if (!isset($this->options['region'])) {
52 1
            throw new UnexpectedValueException("Missing 'region' as option");
53
        }
54
55 2
        if (!isset($this->options['bucket'])) {
56 1
            throw new UnexpectedValueException("Missing 'bucket' as option");
57
        }
58
59 1
        if (!isset($this->options['prefix'])) {
60 1
            $this->options['prefix'] = null;
61
        }
62
63 1
        if (!isset($this->options['request.options'])) {
64 1
            $this->options['request.options'] = [];
65
        }
66 1
    }
67
}
68