Completed
Push — master ( a0e8ce...60fa13 )
by Bas
12s
created

WebDAVAdapterFactory::doCreateService()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 15
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2.2109

Importance

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