Completed
Push — master ( a0e8ce...60fa13 )
by Bas
12s
created

WebDAVAdapterFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 78.56%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 35
loc 35
ccs 11
cts 14
cp 0.7856
rs 10
c 1
b 0
f 0

2 Methods

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