DropboxAdapterFactory::validateConfig()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 0
cp 0
rs 9.9332
c 0
b 0
f 0
cc 3
nc 3
nop 0
crap 12
1
<?php
2
3
/**
4
 * BsbFlystem
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @see       https://bushbaby.nl/
10
 *
11
 * @copyright Copyright (c) 2014-2021 bushbaby multimedia. (https://bushbaby.nl)
12
 * @author    Bas Kamer <[email protected]>
13
 * @license   MIT
14
 *
15 1
 * @package   bushbaby/flysystem
16
 */
17 1
18
declare(strict_types=1);
19
20
namespace BsbFlysystem\Adapter\Factory;
21
22
use BsbFlysystem\Exception\RequirementsException;
23
use BsbFlysystem\Exception\UnexpectedValueException;
24 1
use League\Flysystem\AdapterInterface;
25 1
use Psr\Container\ContainerInterface;
26
use Spatie\Dropbox\Client;
27
use Spatie\FlysystemDropbox\DropboxAdapter as Adapter;
28 1
29
class DropboxAdapterFactory extends AbstractAdapterFactory
30 1
{
31
    public function doCreateService(ContainerInterface $container): AdapterInterface
32
    {
33 3
        if (! \class_exists(Adapter::class)) {
34
            throw new RequirementsException(['spatie/flysystem-dropbox'], 'Dropbox');
35 3
        }
36 1
37
        $client = new Client(
38
            $this->options['access_token']
39 2
        );
40 2
41
        return new Adapter($client, $this->options['prefix']);
42 2
    }
43
44
    protected function validateConfig(): void
45
    {
46
        if (! isset($this->options['access_token'])) {
47
            throw new UnexpectedValueException("Missing 'access_token' as option");
48
        }
49
50
        if (! isset($this->options['prefix'])) {
51
            $this->options['prefix'] = '';
52
        }
53
    }
54
}
55