Completed
Pull Request — master (#42)
by Florent
12:58
created

DropboxAdapterFactory::validateConfig()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.9332
c 0
b 0
f 0
cc 3
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 Psr\Container\ContainerInterface;
11
use Spatie\FlysystemDropbox\DropboxAdapter as Adapter;
12
13
class DropboxAdapterFactory extends AbstractAdapterFactory
14
{
15
    public function doCreateService(ContainerInterface $container): AdapterInterface
16
    {
17
        if (! class_exists(\Spatie\FlysystemDropbox\DropboxAdapter::class)) {
18
            throw new RequirementsException(
19
                ['spatie/flysystem-dropbox'],
20
                'Dropbox'
21
            );
22
        }
23
24
        $client = new \Spatie\Dropbox\Client(
25
            $this->options['access_token']
26
        );
27
28
        $adapter = new Adapter($client, $this->options['prefix']);
29
30
        return $adapter;
31
    }
32
33 2
    protected function validateConfig()
34
    {
35 2
        if (! isset($this->options['access_token'])) {
36 1
            throw new UnexpectedValueException("Missing 'access_token' as option");
37
        }
38
39 1
        if (! isset($this->options['prefix'])) {
40 1
            $this->options['prefix'] = '';
41
        }
42 1
    }
43
}
44