WebDAVAdapterFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 24
loc 24
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A doCreateService() 10 10 2
A validateConfig() 10 10 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
 * @package   bushbaby/flysystem
16 1
 */
17
18 1
declare(strict_types=1);
19
20
namespace BsbFlysystem\Adapter\Factory;
21
22
use BsbFlysystem\Exception\RequirementsException;
23
use BsbFlysystem\Exception\UnexpectedValueException;
24
use League\Flysystem\AdapterInterface;
25 1
use League\Flysystem\WebDAV\WebDAVAdapter as Adapter;
26
use Psr\Container\ContainerInterface;
27 1
use Sabre\DAV\Client;
28
29 1 View Code Duplication
class WebDAVAdapterFactory extends AbstractAdapterFactory
30
{
31
    public function doCreateService(ContainerInterface $container): AdapterInterface
32 3
    {
33
        if (! \class_exists(Adapter::class)) {
34 3
            throw new RequirementsException(['league/flysystem-webdav'], 'WebDAV');
35 1
        }
36
37
        $client = new Client($this->options);
38 2
39 2
        return new Adapter($client, $this->options['prefix']);
40
    }
41 2
42
    protected function validateConfig(): void
43
    {
44
        if (! isset($this->options['baseUri'])) {
45
            throw new UnexpectedValueException("Missing 'baseUri' as option");
46
        }
47
48
        if (! isset($this->options['prefix'])) {
49
            $this->options['prefix'] = null;
50
        }
51
    }
52
}
53