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

DropboxAdapterFactory::doCreateService()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 11

Duplication

Lines 19
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 19
loc 19
ccs 8
cts 8
cp 1
rs 9.4285
cc 2
eloc 11
nc 2
nop 1
crap 2
1
<?php
2
3
namespace BsbFlysystem\Adapter\Factory;
4
5
use BsbFlysystem\Exception\RequirementsException;
6
use BsbFlysystem\Exception\UnexpectedValueException;
7
use League\Flysystem\Dropbox\DropboxAdapter as Adapter;
8
use Zend\ServiceManager\FactoryInterface;
9
use Zend\ServiceManager\ServiceLocatorInterface;
10
11
class DropboxAdapterFactory extends AbstractAdapterFactory
12
{
13
    /**
14
     * @inheritdoc
15
     */
16 1 View Code Duplication
    public function doCreateService(ServiceLocatorInterface $serviceLocator)
17
    {
18
        if (!class_exists(\League\Flysystem\Dropbox\DropboxAdapter::class)) {
19
            throw new RequirementsException(
20
                ['league/flysystem-dropbox'],
21
                'Dropbox'
22
            );
23
        }
24
25 1
        $client = new \Dropbox\Client(
26 1
            $this->options['access_token'],
27 1
            $this->options['client_identifier'],
28 1
            $this->options['user_locale']
29 1
        );
30
31 1
        $adapter = new Adapter($client, $this->options['prefix']);
32
33 1
        return $adapter;
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39
    protected function validateConfig()
40
    {
41
        if (!isset($this->options['access_token'])) {
42
            throw new UnexpectedValueException("Missing 'access_token' as option");
43
        }
44
45
        if (!isset($this->options['client_identifier'])) {
46
            throw new UnexpectedValueException("Missing 'client_identifier' as option");
47
        }
48
49
        if (!isset($this->options['user_locale'])) {
50
            $this->options['user_locale'] = null;
51
        }
52
53
        if (!isset($this->options['prefix'])) {
54
            $this->options['prefix'] = null;
55
        }
56
    }
57
}
58