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

DropboxAdapterFactory::validateConfig()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 18
ccs 0
cts 0
cp 0
rs 8.8571
cc 5
eloc 9
nc 6
nop 0
crap 30
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