ReplicateFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 72.72%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 14
dl 0
loc 27
ccs 8
cts 11
cp 0.7272
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 18 4
1
<?php
2
3
/**
4
 * Copyright (c) Florian Krämer (https://florian-kraemer.net)
5
 * Licensed under The MIT License
6
 * For full copyright and license information, please see the LICENSE.txt
7
 * Redistributions of files must retain the above copyright notice.
8
 *
9
 * @copyright Copyright (c) Florian Krämer (https://florian-kraemer.net)
10
 * @author    Florian Krämer
11
 * @link      https://github.com/Phauthentic
12
 * @license   https://opensource.org/licenses/MIT MIT License
13
 */
14
15
declare(strict_types=1);
16
17
namespace Phauthentic\Infrastructure\Storage\Factories;
18
19
use League\Flysystem\AdapterInterface;
20
use League\Flysystem\Replicate\ReplicateAdapter;
21
use Phauthentic\Infrastructure\Storage\Exception\PackageRequiredException;
22
use Phauthentic\Infrastructure\Storage\Factories\Exception\FactoryException;
23
24
/**
25
 * ReplicateFactory
26
 */
27
class ReplicateFactory extends AbstractFactory
28
{
29
    protected string $alias = 'replicate';
30
    protected ?string $package = 'league/flysystem-replicate-adapter';
31
    protected string $className = ReplicateAdapter::class;
32
33
    /**
34
     * @inheritDoc
35
     */
36 3
    public function build(array $config): AdapterInterface
37
    {
38 3
        if (!class_exists(ReplicateAdapter::class)) {
39
            throw PackageRequiredException::fromAdapterAndPackageNames(
40
                'replicate',
41
                'league/flysystem-replicate-adapter'
42
            );
43
        }
44
45 3
        if (!isset($config['source']) || !isset($config['target'])) {
46 2
            throw new FactoryException(
47 2
                'You must configure `source` and `target`'
48
            );
49
        }
50
51 1
        return new ReplicateAdapter(
52 1
            $config['source'],
53 1
            $config['target']
54
        );
55
    }
56
}
57