Completed
Push — master ( a0e8ce...60fa13 )
by Bas
12s
created

DropboxAdapterFactory::validateConfig()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 3

Importance

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