Conditions | 4 |
Paths | 4 |
Total Lines | 72 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
37 | public function init(ModuleManagerInterface $manager) |
||
38 | { |
||
39 | if (!($manager instanceof ModuleManager)) { |
||
|
|||
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); |
||
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 | |||
118 |
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 thecomposer.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
orrequire-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 you have not tested against this specific condition, such errors might go unnoticed.