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

DropboxAdapterFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 40%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 31
ccs 6
cts 15
cp 0.4
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateConfig() 0 10 3
A doCreateService() 0 17 2
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