| Conditions | 2 |
| Paths | 1 |
| Total Lines | 57 |
| Code Lines | 36 |
| 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 |
||
| 176 | private function getContainerMock() |
||
| 177 | { |
||
| 178 | $mock = $this->prophesize(ContainerInterface::class); |
||
| 179 | $kernel = $this->prophesize(KernelInterface::class); |
||
| 180 | $resolver = $this->prophesize(ControllerResolverInterface::class); |
||
| 181 | $resolver->getController(Argument::type(RpcRequestInterface::class))->willReturn( |
||
| 182 | function (JsonRpcRequestInterface $request) { |
||
| 183 | if ($request->getMethod() === 'exception') { |
||
| 184 | throw new \LogicException('Failure!'); |
||
| 185 | } |
||
| 186 | |||
| 187 | return new JsonRpcResponse($request->getId(), (object)['success' => true]); |
||
| 188 | } |
||
| 189 | ); |
||
| 190 | $resolver->getArguments(Argument::type(RpcRequestInterface::class), Argument::any())->will( |
||
| 191 | function (array $args) { |
||
| 192 | return [ |
||
| 193 | $args[0], |
||
| 194 | ]; |
||
| 195 | } |
||
| 196 | ); |
||
| 197 | |||
| 198 | $evm = $this->prophesize(EventDispatcherInterface::class); |
||
| 199 | $evm->dispatch(Argument::exact(RpcEvents::EXCEPTION), Argument::type(GetExceptionResponseEvent::class)) |
||
| 200 | ->will( |
||
| 201 | function ($args) { |
||
| 202 | /** @var GetExceptionResponseEvent $event */ |
||
| 203 | $event = $args[1]; |
||
| 204 | |||
| 205 | /** @var JsonRpcRequestInterface $request */ |
||
| 206 | $request = $event->getRequest(); |
||
| 207 | |||
| 208 | $event->setResponse( |
||
| 209 | new JsonRpcResponse( |
||
| 210 | $request->getId(), |
||
| 211 | null, new JsonRpcError( |
||
| 212 | JsonRpcError::INTERNAL_ERROR, |
||
| 213 | $event->getException()->getMessage() |
||
| 214 | ) |
||
| 215 | ) |
||
| 216 | ); |
||
| 217 | } |
||
| 218 | ); |
||
| 219 | $evm->dispatch(Argument::exact(RpcEvents::FINISH_REQUEST), Argument::type(FinishRequestEvent::class)) |
||
| 220 | ->willReturn(null); |
||
| 221 | $evm->dispatch(Argument::exact(RpcEvents::CONTROLLER), Argument::type(FilterControllerEvent::class)) |
||
| 222 | ->willReturn(null); |
||
| 223 | $evm->dispatch(Argument::exact(RpcEvents::REQUEST), Argument::type(GetResponseEvent::class))->willReturn(null); |
||
| 224 | $evm->dispatch(Argument::exact(RpcEvents::RESPONSE), Argument::type(FilterResponseEvent::class)) |
||
| 225 | ->willReturn(null); |
||
| 226 | |||
| 227 | $mock->get(Argument::exact('jsonrpc_server.controller_resolver'))->willReturn($resolver->reveal()); |
||
| 228 | $mock->get(Argument::exact('event_dispatcher'))->willReturn($evm->reveal()); |
||
| 229 | $mock->get(Argument::exact('kernel'))->willReturn($kernel->reveal()); |
||
| 230 | |||
| 231 | return $mock->reveal(); |
||
| 232 | } |
||
| 233 | |||
| 242 |