ZipArchiveAdapterFactory::validateConfig()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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