Conditions | 5 |
Paths | 4 |
Total Lines | 72 |
Lines | 0 |
Ratio | 0 % |
Changes | 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) && $services->has(DebuggerFactory::SERVICE)) { |
||
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 check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.