Completed
Pull Request — master (#3)
by
unknown
02:10
created

S3AdapterFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 28
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 25 2
1
<?php
2
declare(strict_types=1);
3
4
namespace WShafer\PSR11FlySystem\Adaptor;
5
6
use Aws\S3\S3Client;
7
use League\Flysystem\AwsS3v3\AwsS3Adapter;
8
use WShafer\PSR11FlySystem\FactoryInterface;
9
10
class S3AdapterFactory implements FactoryInterface
11
{
12
    public function __invoke(array $options)
13
    {
14
        $options = array_replace([
15
            'key' => null,
16
            'secret' => null,
17
            'region' => 'us-east-1',
18
            'version' => 'latest',
19
            'bucket' => null,
20
            'prefix' => null,
21
        ], $options);
22
23
        $bucket = $options['bucket'];
24
        $prefix = $options['prefix'];
25
26
        if (!array_key_exists('credentials', $options)) {
27
            $credentials = [];
28
            $credentials['key']  = $options['key'];
29
            $credentials['secret'] = $options['secret'];
30
            $options['credentials'] = $credentials;
31
        }
32
33
        $client = new S3Client($options);
34
35
        return new AwsS3Adapter($client, $bucket, $prefix);
36
    }
37
}
38