Completed
Push — master ( 60fa13...455325 )
by Bas
15:24
created

DropboxAdapterFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 31
loc 31
ccs 12
cts 15
cp 0.8
rs 10
c 0
b 0
f 0

2 Methods

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