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

AdapterManager::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 10
ccs 8
cts 8
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 2
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 AdapterManager extends AbstractPluginManager
10
{
11
    /**
12
     * @inheritDoc
13
     */
14
    protected $instanceOf = \League\Flysystem\AdapterInterface::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
    protected $factories = [
30
        'League\Flysystem\Adapter\NullAdapter' => \Zend\ServiceManager\Factory\InvokableFactory::class,
31
        'leagueflysystemadapternulladapter'    => \Zend\ServiceManager\Factory\InvokableFactory::class,
32
    ];
33
34
    /**
35
     * @inheritDoc
36
     */
37 7 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...
38
    {
39 7
        if (!$instance instanceof $this->instanceOf) {
40 1
            throw new Exception\InvalidServiceException(sprintf(
41 1
                'Invalid adapter "%s" created; not an instance of %s',
42 1
                get_class($instance),
43 1
                $this->instanceOf
44 1
            ));
45
        }
46 7
    }
47
48
    /**
49
     * {@inheritDoc}
50
     */
51 1
    public function validatePlugin($instance)
52
    {
53
        try {
54 1
            $this->validate($instance);
55 1
        } catch (Exception\InvalidServiceException $e) {
56 1
            throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
57
        }
58 1
    }
59
}
60