Completed
Push — master ( 0339b7...e81256 )
by Bas
7s
created

FilesystemManager   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 23.26 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validatePlugin() 0 8 2
A validate() 10 10 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
namespace BsbFlysystem\Service;
4
5
use BsbFlysystem\Exception\RuntimeException;
6
use Zend\ServiceManager\AbstractPluginManager;
7
use Zend\ServiceManager\Exception;
8
9
class FilesystemManager extends AbstractPluginManager
10
{
11
    /**
12
     * @inheritDoc
13
     */
14
    protected $instanceOf = \League\Flysystem\FilesystemInterface::class;
15
16
    /**
17
     * @inheritDoc
18
     */
19
    protected $shareByDefault = true;
20
21
    /**
22
     * @inheritDoc
23
     */
24
    protected $sharedByDefault = true;
25
26
    /**
27
     * @inheritDoc
28
     */
29 5 View Code Duplication
    public function validate($instance)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
    {
31 5
        if (!$instance instanceof $this->instanceOf) {
32 1
            throw new Exception\InvalidServiceException(sprintf(
33 1
                'Invalid filesystem "%s" created; not an instance of %s',
34 1
                get_class($instance),
35 1
                $this->instanceOf
36 1
            ));
37
        }
38 5
    }
39
40
    /**
41
     * {@inheritDoc}
42
     */
43 1
    public function validatePlugin($instance)
44
    {
45
        try {
46 1
            $this->validate($instance);
47 1
        } catch (Exception\InvalidServiceException $e) {
48 1
            throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
49
        }
50 1
    }
51
}
52