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

ReplicateAdapterFactory::doCreateService()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.108

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 7
cts 10
cp 0.7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 1
crap 2.108
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