AwsS3AdapterFactory::createAdapter()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 5
c 1
b 0
f 1
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 10
cc 3
nc 2
nop 1
crap 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 3
    public static function createAdapter(array $config)
18
    {
19 3
        if(!isset($config['bucket']) or !is_string($config['bucket'])) {
20 2
            $message = sprintf('Configuration for s3 is broken. Configuration must contains bucket parameter with string type.');
21 2
            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