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

WebDAVAdapterFactory::doCreateService()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 15
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 15
loc 15
ccs 0
cts 8
cp 0
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
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