| Conditions | 13 |
| Paths | 4 |
| Total Lines | 90 |
| Code Lines | 40 |
| 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 |
||
| 30 | public function init(ModuleManagerInterface $modules) |
||
| 31 | { |
||
| 32 | /** @var \Zend\ModuleManager\ModuleManager $modules */ |
||
| 33 | /** @var ServiceManager $services */ |
||
| 34 | $services = $modules->getEvent()->getParam('ServiceManager'); |
||
|
|
|||
| 35 | $services->setFactory(ModuleOptions::class, ModuleOptionsFactory::class); |
||
| 36 | $services->setFactory(DebuggerFactory::SERVICE, DebuggerFactory::class); |
||
| 37 | |||
| 38 | /** @var ModuleOptions $options */ |
||
| 39 | $options = $services->get(ModuleOptions::class); |
||
| 40 | |||
| 41 | // set error log path |
||
| 42 | ini_set('error_log', $options->getPhpErrorLog()); |
||
| 43 | |||
| 44 | // return early when disabled |
||
| 45 | if ($options->isDisabled()) { |
||
| 46 | return; |
||
| 47 | } |
||
| 48 | |||
| 49 | // init debugger |
||
| 50 | $this->sessionStart(); |
||
| 51 | /** @var Service\Debugger $debugger */ |
||
| 52 | $debugger = $services->get(DebuggerFactory::SERVICE); |
||
| 53 | |||
| 54 | // add a service initializer |
||
| 55 | // TODO something better |
||
| 56 | $modules->getEventManager()->attach( |
||
| 57 | ModuleEvent::EVENT_LOAD_MODULES_POST, |
||
| 58 | function () use ($services, $debugger) { |
||
| 59 | |||
| 60 | $initializer = function ($obj) use ($debugger) { |
||
| 61 | if ($obj instanceof Service\DebuggerAwareInterface) { |
||
| 62 | /** @var Service\Debugger $debugger */ |
||
| 63 | $obj->setDebugger($debugger); |
||
| 64 | } |
||
| 65 | }; |
||
| 66 | |||
| 67 | $services->addInitializer($initializer); |
||
| 68 | foreach ($services->getRegisteredServices()['instances'] as $name) { |
||
| 69 | $instance = $services->get($name); |
||
| 70 | ($instance instanceof ServiceManager) and $instance->addInitializer($initializer); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | ); |
||
| 74 | |||
| 75 | // return early on null debugger |
||
| 76 | if ($debugger instanceof NullDebugger) { |
||
| 77 | return; |
||
| 78 | } |
||
| 79 | |||
| 80 | // create bar panels |
||
| 81 | $showBar = $options->showBar(); |
||
| 82 | $barPanels = $options->getBarPanels(); |
||
| 83 | |||
| 84 | if ($showBar) { |
||
| 85 | // set core bar panels |
||
| 86 | foreach ($barPanels as $id => $barPanel) { |
||
| 87 | $debugger->setBarPanel(new $barPanel($modules), $id); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | // finish debugger init |
||
| 92 | $modules->getEventManager()->attach( |
||
| 93 | ModuleEvent::EVENT_LOAD_MODULES_POST, |
||
| 94 | function () use ($services, $debugger, $options, $showBar, $barPanels) { |
||
| 95 | |||
| 96 | // update module options |
||
| 97 | /** @var ModuleOptions $newOptions */ |
||
| 98 | $newOptions = $services->create(ModuleOptions::class); |
||
| 99 | $options->setFromArray($newOptions->toArray()); |
||
| 100 | |||
| 101 | if ($showBar) { |
||
| 102 | // set additional bar panels |
||
| 103 | $newBarPanels = array_diff($options->getBarPanels(), $barPanels); |
||
| 104 | foreach ($newBarPanels as $id => $barPanel) { |
||
| 105 | $debugger->setBarPanel($services->get($barPanel), $id); |
||
| 106 | } |
||
| 107 | |||
| 108 | // init bar panels |
||
| 109 | foreach ($debugger->getBarPanels() as $barPanel) { |
||
| 110 | ($barPanel instanceof Debugger\PanelInitInterface) and $barPanel->init($services); |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | // debugger templates |
||
| 115 | $templateMap = $options->getTemplateMap(); |
||
| 116 | empty($templateMap) or $services->get('ViewTemplateMapResolver')->merge($templateMap); |
||
| 117 | } |
||
| 118 | ); |
||
| 119 | } |
||
| 120 | |||
| 136 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.