Completed
Push — master ( 63cdb6...e2968d )
by Bas
06:46 queued 04:49
created

ReplicateAdapterFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 81.25%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 38
ccs 13
cts 16
cp 0.8125
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A doCreateService() 0 18 2
A validateConfig() 0 10 3
1
<?php
2
3
namespace BsbFlysystem\Adapter\Factory;
4
5
use BsbFlysystem\Exception\RequirementsException;
6
use BsbFlysystem\Exception\UnexpectedValueException;
7
use League\Flysystem\Replicate\ReplicateAdapter as Adapter;
8
use Zend\ServiceManager\FactoryInterface;
9
use Zend\ServiceManager\ServiceLocatorInterface;
10
11
class ReplicateAdapterFactory extends AbstractAdapterFactory
12
{
13
    /**
14
     * @inheritdoc
15
     */
16 1
    public function doCreateService(ServiceLocatorInterface $serviceLocator)
17
    {
18 1
        if (!class_exists(\League\Flysystem\Replicate\ReplicateAdapter::class)) {
19
            throw new RequirementsException(
20
                ['league/flysystem-replicate-adapter'],
21
                'Replicate'
22
            );
23
        }
24
25 1
        $connectionManager = $serviceLocator->get('BsbFlysystemAdapterManager');
26
27 1
        $adapter = new Adapter(
28 1
            $connectionManager->get($this->options['source']),
29 1
            $connectionManager->get($this->options['replicate'])
30
        );
31
32 1
        return $adapter;
33
    }
34
35
    /**
36
     * @inheritdoc
37
     */
38 4
    protected function validateConfig()
39
    {
40 4
        if (!isset($this->options['source'])) {
41 1
            throw new UnexpectedValueException("Missing 'source' as option");
42
        }
43
44 3
        if (!isset($this->options['replicate'])) {
45 1
            throw new UnexpectedValueException("Missing 'replicate' as option");
46
        }
47 2
    }
48
}
49