AdapterManager   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 7.32 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 3
loc 41
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 3 6 2
A validatePlugin() 0 8 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
/**
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
 * @package   bushbaby/flysystem
16
 */
17
18
declare(strict_types=1);
19
20
namespace BsbFlysystem\Service;
21
22
use BsbFlysystem\Exception\RuntimeException;
23
use Laminas\ServiceManager\AbstractPluginManager;
24
use Laminas\ServiceManager\Exception;
25
use Laminas\ServiceManager\Factory\InvokableFactory;
26
use League\Flysystem\AdapterInterface;
27
28
class AdapterManager extends AbstractPluginManager
29
{
30
    /**
31
     * @var string
32
     */
33
    protected $instanceOf = AdapterInterface::class;
34
35
    /**
36 7
     * @var bool
37
     */
38 7
    protected $shareByDefault = true;
39 1
40 1
    /**
41 1
     * @var bool
42 1
     */
43
    protected $sharedByDefault = true;
44
45 7
    /**
46
     * @var array
47 1
     */
48
    protected $factories = [
49
        \League\Flysystem\Adapter\NullAdapter::class => InvokableFactory::class,
50 1
        'leagueflysystemadapternulladapter' => InvokableFactory::class,
51 1
    ];
52 1
53
    public function validate($instance): void
54 1
    {
55 View Code Duplication
        if (! $instance instanceof $this->instanceOf) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
56
            throw new Exception\InvalidServiceException(\sprintf('Invalid adapter "%s" created; not an instance of %s', \get_class($instance), $this->instanceOf));
57
        }
58
    }
59
60
    public function validatePlugin($instance): void
61
    {
62
        try {
63
            $this->validate($instance);
64
        } catch (Exception\InvalidServiceException $e) {
65
            throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
66
        }
67
    }
68
}
69