Completed
Pull Request — master (#5)
by Chris
08:31
created

S3AdapterFactory::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 0
cts 13
cp 0
rs 9.6
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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
        $key = $options['key'] ?? null;
15
        $secret = $options['secret'] ?? null;
16
        $region = $options['region'] ?? 'us-east-1';
17
        $version = $options['version'] ?? 'latest';
18
        $bucket = $options['bucket'] ?? null;
19
        $prefix = $options['prefix'] ?? null;
20
21
        $client = new S3Client([
22
            'version'     => $version,
23
            'region'      => $region,
24
            'credentials' => [
25
                'key'    => $key,
26
                'secret' => $secret
27
            ]
28
        ]);
29
30
        return new AwsS3Adapter($client, $bucket, $prefix);
31
    }
32
}
33