Completed
Pull Request — master (#5)
by
unknown
03:04
created

AwsS3AdapterFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 3
eloc 6
dl 0
loc 17
ccs 4
cts 6
cp 0.6667
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A createAdapter() 0 10 3
1
<?php
2
3
namespace Lamoda\Codeception\Extension\AdapterFactory;
4
5
use Codeception\Exception\ModuleConfigException;
6
use League\Flysystem\AdapterInterface;
7
use Aws\S3\S3Client;
8
use League\Flysystem\AwsS3v3\AwsS3Adapter;
9
10
class AwsS3AdapterFactory implements AdapterFactoryInterface
11
{
12
    /**
13
     * @param array $config
14
     *
15
     * @return AdapterInterface
16
     */
17 1
    public static function createAdapter(array $config)
18
    {
19 1
        if(!isset($config['bucket']) or !is_string($config['bucket'])) {
20
            $message = sprintf('Configuration for s3 is broken. Configuration must contains bucket parameter with string type.');
21
            throw new ModuleConfigException(__CLASS__, $message);
22
        }
23
24 1
        $client = new S3Client($config);
25
26 1
        return new AwsS3Adapter($client, $config['bucket']);
27
    }
28
}
29