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

DropboxAdapterFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 40%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 37
loc 37
ccs 6
cts 15
cp 0.4
rs 10
c 0
b 0
f 0

2 Methods

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