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

S3AdapterFactory::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 0
cts 13
cp 0
rs 9.52
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
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