Completed
Push — master ( 9b2eb4...595a6b )
by Bas
05:39
created

CopyAdapterFactory   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 38.46 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 0 Features 0
Metric Value
wmc 8
c 7
b 0
f 0
lcom 1
cbo 5
dl 20
loc 52
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A doCreateService() 20 20 2
B validateConfig() 0 22 6

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 Barracuda\Copy\API;
6
use BsbFlysystem\Exception\RequirementsException;
7
use BsbFlysystem\Exception\UnexpectedValueException;
8
use League\Flysystem\Copy\CopyAdapter as Adapter;
9
use Zend\ServiceManager\FactoryInterface;
10
use Zend\ServiceManager\ServiceLocatorInterface;
11
12
class CopyAdapterFactory extends AbstractAdapterFactory
13
{
14
    /**
15
     * @inheritdoc
16
     */
17 1 View Code Duplication
    public function doCreateService(ServiceLocatorInterface $serviceLocator)
18
    {
19
        if (!class_exists(\League\Flysystem\Copy\CopyAdapter::class)) {
20
            throw new RequirementsException(
21
                ['league/flysystem-copy'],
22
                'Copy'
23
            );
24
        }
25
26 1
        $client = new API(
27 1
            $this->options['consumer_key'],
28 1
            $this->options['consumer_secret'],
29 1
            $this->options['access_token'],
30 1
            $this->options['token_secret']
31 1
        );
32
33 1
        $adapter = new Adapter($client, $this->options['prefix']);
34
35 1
        return $adapter;
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41
    protected function validateConfig()
42
    {
43
        if (!isset($this->options['consumer_key'])) {
44
            throw new UnexpectedValueException("Missing 'consumer_key' as option");
45
        }
46
47
        if (!isset($this->options['consumer_secret'])) {
48
            throw new UnexpectedValueException("Missing 'consumer_secret' as option");
49
        }
50
51
        if (!isset($this->options['access_token'])) {
52
            throw new UnexpectedValueException("Missing 'access_token' as option");
53
        }
54
55
        if (!isset($this->options['token_secret'])) {
56
            throw new UnexpectedValueException("Missing 'token_secret' as option");
57
        }
58
59
        if (!isset($this->options['prefix'])) {
60
            $this->options['prefix'] = null;
61
        }
62
    }
63
}
64