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

ZipArchiveAdapterFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 46.15%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 27
loc 27
ccs 6
cts 13
cp 0.4615
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateConfig() 10 10 3
A doCreateService() 13 13 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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