Completed
Pull Request — master (#15)
by Vytautas
10:02
created

CollectionsManager::validate()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 13
ccs 0
cts 0
cp 0
rs 9.2
cc 4
eloc 8
nc 2
nop 1
crap 20
1
<?php
2
3
namespace Svycka\Settings\Collection;
4
5
use Svycka\Settings\Collection\Factory\SettingsCollectionAbstractFactory;
6
use Zend\ServiceManager\AbstractPluginManager;
7
use Zend\ServiceManager\Exception\InvalidServiceException;
8
9
/**
10
 * Class CollectionsManager
11
 *
12
 * CollectionsManager implementation for managing settings collection
13
 *
14
 * @method CollectionInterface get($name)
15
 *
16
 * @author Vytautas Stankus <[email protected]>
17
 * @license MIT
18
 */
19
class CollectionsManager extends AbstractPluginManager
20
{
21
    /**
22
     * An object type that the created instance must be instanced of
23
     *
24
     * @var null|string
25
     */
26
    protected $instanceOf = CollectionInterface::class;
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 27
    public function __construct($configInstanceOrParentLocator = null, array $config = [])
32
    {
33 27
        parent::__construct($configInstanceOrParentLocator, $config);
34
35 27
        $this->addAbstractFactory(SettingsCollectionAbstractFactory::class);
36 27
    }
37
38
    /**
39
     * Validate the plugin
40
     *
41
     * Checks that the collection loaded is instance of CollectionInterface.
42
     *
43
     * @param  CollectionInterface $instance
44
     *
45
     * @return void
46
     * @throws InvalidServiceException if invalid
47
     *
48
     * @deprecated will be removed after zf2 support drop (only required to prevent deprecated warning)
49
     */
50
    public function validate($instance)
51
    {
52
        if (empty($this->instanceOf) || $instance instanceof $this->instanceOf) {
53
            return;
54
        }
55
56
        throw new InvalidServiceException(sprintf(
57
            'Plugin manager "%s" expected an instance of type "%s", but "%s" was received',
58
            __CLASS__,
59
            $this->instanceOf,
60
            is_object($instance) ? get_class($instance) : gettype($instance)
61
        ));
62
    }
63
64
    /**
65
     * Validate the plugin
66
     *
67
     * Checks that the collection loaded is instance of CollectionInterface.
68
     *
69
     * @param  CollectionInterface $instance
70
     *
71
     * @return void
72
     * @throws InvalidServiceException if invalid
73
     *
74
     * @deprecated will be removed after zf2 support drop
75
     */
76
    public function validatePlugin($instance)
77
    {
78
        $this->validate($instance);
0 ignored issues
show
Deprecated Code introduced by
The method Svycka\Settings\Collecti...ionsManager::validate() has been deprecated with message: will be removed after zf2 support drop (only required to prevent deprecated warning)

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
79
    }
80
}
81