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

WebDAVAdapterFactory::validateConfig()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

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.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 League\Flysystem\WebDAV\WebDAVAdapter as Adapter;
11
use Psr\Container\ContainerInterface;
12
use Sabre\DAV\Client;
13
14 View Code Duplication
class WebDAVAdapterFactory extends AbstractAdapterFactory
15
{
16
    public function doCreateService(ContainerInterface $container): AdapterInterface
17
    {
18
        if (! class_exists(\League\Flysystem\WebDAV\WebDAVAdapter::class)) {
19
            throw new RequirementsException(
20
                ['league/flysystem-webdav'],
21
                'WebDAV'
22
            );
23
        }
24
25
        $client = new Client($this->options);
26
27
        $adapter = new Adapter($client, $this->options['prefix']);
28
29
        return $adapter;
30
    }
31
32 2
    protected function validateConfig()
33
    {
34 2
        if (! isset($this->options['baseUri'])) {
35 1
            throw new UnexpectedValueException("Missing 'baseUri' as option");
36
        }
37
38 1
        if (! isset($this->options['prefix'])) {
39 1
            $this->options['prefix'] = null;
40
        }
41 1
    }
42
}
43