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

ReplicateAdapterFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 37.5%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 32
ccs 6
cts 16
cp 0.375
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateConfig() 0 10 3
A doCreateService() 0 18 2
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