Completed
Push — master ( 9b2eb4...595a6b )
by Bas
05:39
created

ReplicateAdapterFactory::validateConfig()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 10
ccs 0
cts 0
cp 0
rs 9.4285
cc 3
eloc 5
nc 3
nop 0
crap 12
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
        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 1
        );
31
32 1
        return $adapter;
33
    }
34
35
    /**
36
     * @inheritdoc
37
     */
38
    protected function validateConfig()
39
    {
40
        if (!isset($this->options['source'])) {
41
            throw new UnexpectedValueException("Missing 'source' as option");
42
        }
43
44
        if (!isset($this->options['replicate'])) {
45
            throw new UnexpectedValueException("Missing 'replicate' as option");
46
        }
47
    }
48
}
49