ReplicateAdapterFactory::validateConfig()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 0
cp 0
rs 9.9332
c 0
b 0
f 0
cc 3
nc 3
nop 0
crap 12
1
<?php
2
3
/**
4
 * BsbFlystem
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @see       https://bushbaby.nl/
10
 *
11
 * @copyright Copyright (c) 2014-2021 bushbaby multimedia. (https://bushbaby.nl)
12
 * @author    Bas Kamer <[email protected]>
13
 * @license   MIT
14
 *
15 1
 * @package   bushbaby/flysystem
16
 */
17 1
18
declare(strict_types=1);
19
20
namespace BsbFlysystem\Adapter\Factory;
21
22
use BsbFlysystem\Exception\RequirementsException;
23
use BsbFlysystem\Exception\UnexpectedValueException;
24 1
use League\Flysystem\AdapterInterface;
25
use League\Flysystem\Replicate\ReplicateAdapter as Adapter;
26 1
use Psr\Container\ContainerInterface;
27 1
28 1
class ReplicateAdapterFactory extends AbstractAdapterFactory
29
{
30
    public function doCreateService(ContainerInterface $container): AdapterInterface
31 1
    {
32
        if (! \class_exists(Adapter::class)) {
33
            throw new RequirementsException(['league/flysystem-replicate-adapter'], 'Replicate');
34 4
        }
35
36 4
        $connectionManager = $container->get('BsbFlysystemAdapterManager');
37 1
38
        return new Adapter(
39
            $connectionManager->get($this->options['source']),
40 3
            $connectionManager->get($this->options['replicate'])
41 1
        );
42
    }
43 2
44
    protected function validateConfig(): void
45
    {
46
        if (! isset($this->options['source'])) {
47
            throw new UnexpectedValueException("Missing 'source' as option");
48
        }
49
50
        if (! isset($this->options['replicate'])) {
51
            throw new UnexpectedValueException("Missing 'replicate' as option");
52
        }
53
    }
54
}
55