WebDAVAdapterFactory::doCreateService()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 5
cts 5
cp 1
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
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
 * @package   bushbaby/flysystem
16 1
 */
17
18 1
declare(strict_types=1);
19
20
namespace BsbFlysystem\Adapter\Factory;
21
22
use BsbFlysystem\Exception\RequirementsException;
23
use BsbFlysystem\Exception\UnexpectedValueException;
24
use League\Flysystem\AdapterInterface;
25 1
use League\Flysystem\WebDAV\WebDAVAdapter as Adapter;
26
use Psr\Container\ContainerInterface;
27 1
use Sabre\DAV\Client;
28
29 1 View Code Duplication
class WebDAVAdapterFactory extends AbstractAdapterFactory
30
{
31
    public function doCreateService(ContainerInterface $container): AdapterInterface
32 3
    {
33
        if (! \class_exists(Adapter::class)) {
34 3
            throw new RequirementsException(['league/flysystem-webdav'], 'WebDAV');
35 1
        }
36
37
        $client = new Client($this->options);
38 2
39 2
        return new Adapter($client, $this->options['prefix']);
40
    }
41 2
42
    protected function validateConfig(): void
43
    {
44
        if (! isset($this->options['baseUri'])) {
45
            throw new UnexpectedValueException("Missing 'baseUri' as option");
46
        }
47
48
        if (! isset($this->options['prefix'])) {
49
            $this->options['prefix'] = null;
50
        }
51
    }
52
}
53