Completed
Pull Request — master (#42)
by Florent
12:58
created

ReplicateAdapterFactory::doCreateService()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 10
cp 0
rs 9.6666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BsbFlysystem\Adapter\Factory;
6
7
use BsbFlysystem\Exception\RequirementsException;
8
use BsbFlysystem\Exception\UnexpectedValueException;
9
use League\Flysystem\AdapterInterface;
10
use League\Flysystem\Replicate\ReplicateAdapter as Adapter;
11
use Psr\Container\ContainerInterface;
12
13
class ReplicateAdapterFactory extends AbstractAdapterFactory
14
{
15
    public function doCreateService(ContainerInterface $container): AdapterInterface
16
    {
17
        if (! class_exists(\League\Flysystem\Replicate\ReplicateAdapter::class)) {
18
            throw new RequirementsException(
19
                ['league/flysystem-replicate-adapter'],
20
                'Replicate'
21
            );
22
        }
23
24
        $connectionManager = $container->get('BsbFlysystemAdapterManager');
25
26
        $adapter = new Adapter(
27
            $connectionManager->get($this->options['source']),
28
            $connectionManager->get($this->options['replicate'])
29
        );
30
31
        return $adapter;
32
    }
33
34 3
    protected function validateConfig()
35
    {
36 3
        if (! isset($this->options['source'])) {
37 1
            throw new UnexpectedValueException("Missing 'source' as option");
38
        }
39
40 2
        if (! isset($this->options['replicate'])) {
41 1
            throw new UnexpectedValueException("Missing 'replicate' as option");
42
        }
43 1
    }
44
}
45