Completed
Push — master ( e81256...4b285b )
by Bas
04:59
created

CopyAdapterFactory::doCreateService()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 12

Duplication

Lines 20
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 20
loc 20
ccs 8
cts 8
cp 1
rs 9.4285
cc 2
eloc 12
nc 2
nop 1
crap 2
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
        );
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