| Conditions | 10 | 
| Paths | 81 | 
| Total Lines | 65 | 
| Code Lines | 38 | 
| 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 | ||
| 101 | protected function onPreHandle(PreHandleEvent $event) | ||
| 102 |     { | ||
| 103 | // convert console args to command | ||
| 104 | $this->commandConverter->setArgs($event->getArgs()); | ||
| 105 | $this->commandConverter->setFormat($event->getCommand()->getArgsFormat()); | ||
| 106 | |||
| 107 | /** @var CommandConfig $commandConfig */ | ||
| 108 | $commandConfig = $event->getCommand()->getConfig(); | ||
| 109 |         if ($event->getCommand()->getName() !== 'help') { | ||
| 110 |             if ($commandConfig->className() === null && count($commandConfig->getSubCommandConfigs()) === 0) { | ||
| 111 | throw new \RuntimeException(sprintf( | ||
| 112 | 'The command %s definition must set the className using ->setClass() method', | ||
| 113 | $event->getCommand()->getName() | ||
| 114 | )); | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | $command = $this->commandConverter->getCommandFrom($commandConfig->className()); | ||
| 119 | |||
| 120 | $this->defaultHandler->setIo($event->getIO()); | ||
| 121 | $this->defaultHandler->clearEventHandlers(); | ||
| 122 | |||
| 123 |         if ($commandConfig->preDispatchEventHandler() !== null) { | ||
| 124 | $this->defaultHandler->addPreDispatchEventHandler($commandConfig->preDispatchEventHandler()); | ||
| 125 | } | ||
| 126 | |||
| 127 |         if ($commandConfig->postDispatchEventHandler()) { | ||
| 128 | $this->defaultHandler->addPostDispatchEventHandler($commandConfig->postDispatchEventHandler()); | ||
| 129 | } | ||
| 130 | |||
| 131 | $commandConfig->setEventBus($this->eventBus); | ||
| 132 | $commandConfig->addEventSubscriber($this->defaultHandler); | ||
| 133 | |||
| 134 |         if ($command !== null) { | ||
| 135 |             if ($command instanceof ConsoleCommandInterface) { | ||
| 136 | $command->setIo($event->getIO()); | ||
| 137 | } | ||
| 138 | |||
| 139 |             try { | ||
| 140 | $this->commandBus->dispatch($command); | ||
| 141 | |||
| 142 | $event->setHandled(true); | ||
| 143 | $event->setStatusCode(0); | ||
| 144 |             } catch (NotFoundException $e) { | ||
| 145 | } | ||
| 146 |         } else { | ||
| 147 |             if ($event->getCommand()->getName() !== 'help') { | ||
| 148 |                 $helpCommand = $this->getCommand('help'); | ||
| 149 | |||
| 150 | $args = $event->getArgs(); | ||
| 151 | $args = $helpCommand->parseArgs($args->getRawArgs()); | ||
| 152 |                 $args->setArgument('command', $event->getCommand()->getName()); | ||
| 153 | |||
| 154 |                 $helpConfig = $this->getConfig()->getCommandConfig('help'); | ||
| 155 | |||
| 156 | $commandHandler = $helpConfig->getHandler(); | ||
| 157 | $handlerMethod = $helpConfig->getHandlerMethod(); | ||
| 158 | |||
| 159 | $commandHandler->$handlerMethod($args, $event->getIO(), $helpCommand); | ||
| 160 | |||
| 161 | $event->setHandled(true); | ||
| 162 | $event->setStatusCode(0); | ||
| 163 | } | ||
| 164 | } | ||
| 165 | } | ||
| 166 | } | ||
| 167 | 
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: