Completed
Push — master ( 9b2eb4...595a6b )
by Bas
05:39
created

ZipArchiveAdapterFactory::doCreateService()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 2

Importance

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