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

ZipArchiveAdapterFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 76.92%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 33
loc 33
ccs 10
cts 13
cp 0.7692
rs 10
c 2
b 0
f 0

2 Methods

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

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
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 2
        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 4
    protected function validateConfig()
34
    {
35 4
        if (!isset($this->options['archive'])) {
36 1
            throw new UnexpectedValueException("Missing 'archive' as option");
37
        }
38
39 3
        if (!isset($this->options['prefix'])) {
40 3
            $this->options['prefix'] = null;
41
        }
42 3
    }
43
}
44