Completed
Pull Request — master (#42)
by Florent
12:58
created

WebDAVAdapterFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 42.86%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 29
loc 29
ccs 6
cts 14
cp 0.4286
rs 10
c 0
b 0
f 0

2 Methods

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

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
declare(strict_types=1);
4
5
namespace BsbFlysystem\Adapter\Factory;
6
7
use BsbFlysystem\Exception\RequirementsException;
8
use BsbFlysystem\Exception\UnexpectedValueException;
9
use League\Flysystem\AdapterInterface;
10
use League\Flysystem\WebDAV\WebDAVAdapter as Adapter;
11
use Psr\Container\ContainerInterface;
12
use Sabre\DAV\Client;
13
14 View Code Duplication
class WebDAVAdapterFactory extends AbstractAdapterFactory
15
{
16
    public function doCreateService(ContainerInterface $container): AdapterInterface
17
    {
18
        if (! class_exists(\League\Flysystem\WebDAV\WebDAVAdapter::class)) {
19
            throw new RequirementsException(
20
                ['league/flysystem-webdav'],
21
                'WebDAV'
22
            );
23
        }
24
25
        $client = new Client($this->options);
26
27
        $adapter = new Adapter($client, $this->options['prefix']);
28
29
        return $adapter;
30
    }
31
32 2
    protected function validateConfig()
33
    {
34 2
        if (! isset($this->options['baseUri'])) {
35 1
            throw new UnexpectedValueException("Missing 'baseUri' as option");
36
        }
37
38 1
        if (! isset($this->options['prefix'])) {
39 1
            $this->options['prefix'] = null;
40
        }
41 1
    }
42
}
43