Completed
Push — master ( 63cdb6...e2968d )
by Bas
06:46 queued 04:49
created

WebDAVAdapterFactory::validateConfig()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 10
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
c 1
b 0
f 0
cc 3
eloc 5
nc 3
nop 0
crap 3
1
<?php
2
3
namespace BsbFlysystem\Adapter\Factory;
4
5
use BsbFlysystem\Exception\RequirementsException;
6
use BsbFlysystem\Exception\UnexpectedValueException;
7
use League\Flysystem\WebDAV\WebDAVAdapter as Adapter;
8
use Sabre\DAV\Client;
9
use Zend\ServiceManager\FactoryInterface;
10
use Zend\ServiceManager\ServiceLocatorInterface;
11
12 View Code Duplication
class WebDAVAdapterFactory extends AbstractAdapterFactory
13
{
14
    /**
15
     * @inheritdoc
16
     */
17 1
    public function doCreateService(ServiceLocatorInterface $serviceLocator)
18
    {
19 1
        if (!class_exists(\League\Flysystem\WebDAV\WebDAVAdapter::class)) {
20
            throw new RequirementsException(
21
                ['league/flysystem-webdav'],
22
                'WebDAV'
23
            );
24
        }
25
26 1
        $client = new Client($this->options);
27
28 1
        $adapter = new Adapter($client, $this->options['prefix']);
29
30 1
        return $adapter;
31
    }
32
33
    /**
34
     * @inheritdoc
35
     */
36 3
    protected function validateConfig()
37
    {
38 3
        if (!isset($this->options['baseUri'])) {
39 1
            throw new UnexpectedValueException("Missing 'baseUri' as option");
40
        }
41
42 2
        if (!isset($this->options['prefix'])) {
43 2
            $this->options['prefix'] = null;
44
        }
45 2
    }
46
}
47