Completed
Push — master ( 60fa13...455325 )
by Bas
15:24
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
declare(strict_types=1);
4
5
namespace BsbFlysystem\Adapter\Factory;
6
7
use BsbFlysystem\Exception\RequirementsException;
8
use BsbFlysystem\Exception\UnexpectedValueException;
9
use League\Flysystem\AdapterInterface;
10
use Spatie\FlysystemDropbox\DropboxAdapter as Adapter;
11
use Zend\ServiceManager\ServiceLocatorInterface;
12
13 View Code Duplication
class DropboxAdapterFactory extends AbstractAdapterFactory
14
{
15 1
    public function doCreateService(ServiceLocatorInterface $serviceLocator): AdapterInterface
16
    {
17 1
        if (! class_exists(\Spatie\FlysystemDropbox\DropboxAdapter::class)) {
18
            throw new RequirementsException(
19
                ['spatie/flysystem-dropbox'],
20
                'Dropbox'
21
            );
22
        }
23
24 1
        $client = new \Spatie\Dropbox\Client(
25 1
            $this->options['access_token']
26
        );
27
28 1
        $adapter = new Adapter($client, $this->options['prefix']);
29
30 1
        return $adapter;
31
    }
32
33 3
    protected function validateConfig()
34
    {
35 3
        if (! isset($this->options['access_token'])) {
36 1
            throw new UnexpectedValueException("Missing 'access_token' as option");
37
        }
38
39 2
        if (! isset($this->options['prefix'])) {
40 2
            $this->options['prefix'] = '';
41
        }
42 2
    }
43
}
44