Completed
Push — develop ( 2c1e6b...179509 )
by Peter
01:59
created

src/WebinoDraw/Module.php (2 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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;
12
13
use WebinoDebug\Factory\DebuggerFactory;
14
use WebinoDebug\Service\Debugger;
15
use WebinoDraw\Debugger\Bar\DrawPanel;
16
use WebinoDraw\Draw\HelperPluginManager;
17
use WebinoDraw\Draw\LoopHelperPluginManager;
18
use WebinoDraw\Exception;
19
use WebinoDraw\Factory\HelperPluginManagerFactory;
20
use WebinoDraw\Factory\LoopHelperPluginManagerFactory;
21
use WebinoDraw\ModuleManager\Feature\WebinoDrawHelperProviderInterface;
22
use WebinoDraw\ModuleManager\Feature\WebinoDrawLoopHelperProviderInterface;
23
use Zend\Filter\FilterPluginManager;
24
use Zend\ModuleManager\Feature\ConfigProviderInterface;
25
use Zend\ModuleManager\ModuleEvent;
26
use Zend\ModuleManager\ModuleManager;
27
use Zend\ModuleManager\ModuleManagerInterface;
28
29
/**
30
 * Class Module
31
 */
32
class Module implements ConfigProviderInterface
33
{
34
    /**
35
     * @param ModuleManagerInterface $manager
36
     */
37
    public function init(ModuleManagerInterface $manager)
38
    {
39
        if (!($manager instanceof ModuleManager)) {
0 ignored issues
show
The class Zend\ModuleManager\ModuleManager does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
40
            throw new Exception\LogicException('Expected ' . ModuleManager::class);
41
        }
42
        
43
        $services = $manager->getEvent()->getParam('ServiceManager');
44
45
        // Register draw helper manager
46
        $services->setFactory(
47
            'WebinoDrawHelperManager',
48
            HelperPluginManagerFactory::class
49
        );
50
        $services->get('ServiceListener')->addServiceManager(
51
            'WebinoDrawHelperManager',
52
            'webino_draw_helpers',
53
            WebinoDrawHelperProviderInterface::class,
54
            'getWebinoDrawHelperConfig'
55
        );
56
57
        // Register draw loop helper manager
58
        $services->setFactory(
59
            'WebinoDrawLoopHelperManager',
60
            LoopHelperPluginManagerFactory::class
61
        );
62
        $services->get('ServiceListener')->addServiceManager(
63
            'WebinoDrawLoopHelperManager',
64
            'webino_draw_loop_helpers',
65
            WebinoDrawLoopHelperProviderInterface::class,
66
            'getWebinoDrawLoopHelperConfig'
67
        );
68
69
        // Register a debugger bar panel
70
        if (class_exists(DebuggerFactory::class)) {
71
            $debugger = $services->get(DebuggerFactory::SERVICE);
72
            $debugger instanceof Debugger and $debugger->setBarPanel(new DrawPanel($manager), DrawPanel::ID);
0 ignored issues
show
The class WebinoDebug\Service\Debugger does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
73
        }
74
75
        // Fixing some DI issues but deprecated
76
        $manager->getEventManager()->attach(
77
            ModuleEvent::EVENT_LOAD_MODULES_POST,
78
            function () use ($services) {
79
80
                // TODO: ZF2 issue
81
                // @link https://github.com/zendframework/zf2/issues/4573
82
                $services->get('FilterManager')->addPeeringServiceManager($services);
83
                $services->get('ViewHelperManager')->addPeeringServiceManager($services);
84
                $services->get('ValidatorManager')->addPeeringServiceManager($services);
85
86
                $instances = $services->get('Di')->instanceManager();
87
88
                // TODO: ZF2 DI issue
89
                // @link https://github.com/zendframework/zf2/issues/6290
90
                $instances->addSharedInstance(
91
                    $services->get('ViewHelperManager'),
92
                    HelperPluginManager::class
93
                );
94
                $instances->addSharedInstance(
95
                    $services->get('FilterManager'),
96
                    FilterPluginManager::class
97
                );
98
                $instances->addSharedInstance(
99
                    $services->get('WebinoDrawHelperManager'),
100
                    HelperPluginManager::class
101
                );
102
                $instances->addSharedInstance(
103
                    $services->get('WebinoDrawLoopHelperManager'),
104
                    LoopHelperPluginManager::class
105
                );
106
            }
107
        );
108
    }
109
110
    /**
111
     * @return array
112
     */
113
    public function getConfig()
114
    {
115
        return include __DIR__ . '/../../config/module.config.php';
116
    }
117
}
118