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

ZipArchiveAdapterFactory::doCreateService()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 13
loc 13
ccs 0
cts 7
cp 0
rs 9.8333
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\ZipArchive\ZipArchiveAdapter as Adapter;
11
use Psr\Container\ContainerInterface;
12
13 View Code Duplication
class ZipArchiveAdapterFactory extends AbstractAdapterFactory
14
{
15
    public function doCreateService(ContainerInterface $container): AdapterInterface
16
    {
17
        if (! class_exists(\League\Flysystem\ZipArchive\ZipArchiveAdapter::class)) {
18
            throw new RequirementsException(
19
                ['league/ziparchive'],
20
                'ZipArchive'
21
            );
22
        }
23
24
        $adapter = new Adapter($this->options['archive'], null, $this->options['prefix']);
25
26
        return $adapter;
27
    }
28
29 2
    protected function validateConfig()
30
    {
31 2
        if (! isset($this->options['archive'])) {
32 1
            throw new UnexpectedValueException("Missing 'archive' as option");
33
        }
34
35 1
        if (! isset($this->options['prefix'])) {
36 1
            $this->options['prefix'] = null;
37
        }
38 1
    }
39
}
40