LoopHelperPluginManager::validatePlugin()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 3
nc 2
nop 1
1
<?php
2
/**
3
 * Webino (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino/WebinoDraw for the canonical source repository
6
 * @copyright   Copyright (c) 2012-2017 Webino, s. r. o. (http://webino.sk)
7
 * @author      Peter Bačinský <[email protected]>
8
 * @license     BSD-3-Clause
9
 */
10
11
namespace WebinoDraw\Draw;
12
13
use WebinoDraw\Exception\InvalidHelperException;
14
use WebinoDraw\Draw\LoopHelper\HelperInterface;
15
use Zend\ServiceManager\AbstractPluginManager;
16
17
/**
18
 * Class LoopHelperPluginManager
19
 *
20
 * @method HelperInterface get($name, $options = [], $usePeeringServiceManagers = true)
21
 */
22
class LoopHelperPluginManager extends AbstractPluginManager
23
{
24
    /**
25
     * Default set of helpers
26
     *
27
     * @var array
28
     */
29
    protected $invokableClasses = [
30
        'webinodrawloopitemproperty'   => 'WebinoDraw\Draw\LoopHelper\ItemProperty',
31
        'webinodrawloopelementwrapper' => 'WebinoDraw\Draw\LoopHelper\ElementWrapper',
32
    ];
33
34
    /**
35
     * Validate the plugin
36
     *
37
     * Checks that the loop helper loaded is an instance of LoopHelper\HelperInterface.
38
     *
39
     * @param mixed $plugin
40
     * @throws InvalidHelperException If invalid
41
     */
42
    public function validatePlugin($plugin)
43
    {
44
        if ($plugin instanceof HelperInterface) {
45
            // we're okay
46
            return;
47
        }
48
49
        throw new InvalidHelperException(
50
            sprintf(
51
                'Plugin of type %s is invalid; must implement %s\LoopHelper\HelperInterface',
52
                (is_object($plugin) ? get_class($plugin) : gettype($plugin)),
53
                __NAMESPACE__
54
            )
55
        );
56
    }
57
}
58