Completed
Push — master ( 0513f3...46cdfb )
by Daniel
03:05
created

Handler::handle()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 20
rs 9.4285
cc 3
eloc 10
nc 2
nop 1
1
<?php
2
3
namespace Cmobi\RabbitmqBundle\Rpc;
4
5
use Cmobi\RabbitmqBundle\Rpc\Exception\InvalidBodyAMQPMessageException;
6
use PhpAmqpLib\Message\AMQPMessage;
7
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
8
9
class Handler
10
{
11
    private $resolver;
12
13
    public function __construct()
14
    {
15
        $this->resolver = new ControllerResolver();
16
    }
17
18
    public function handle(AMQPMessage $message)
19
    {
20
21
22
        //$controller = $this->getResolver()->getController($message);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
23
        //$arguments = $this->getResolver()->getArguments($message, $controller);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
24
        $controller = '';
25
        $arguments = [];
26
        $response = call_user_func_array($controller, $arguments);
27
28
        if (!is_string($response) || is_null($response)) {
29
            throw new InvalidBodyAMQPMessageException('Invalid Body: Content should be string and not null.');
30
        }
31
        $amqpResponse = new AMQPMessage(
32
            $response,
33
            ['correlation_id' => $message->get('correlation_id')]
34
        );
35
36
        return $amqpResponse;
37
    }
38
39
    /**
40
     * @return ControllerResolverInterface
41
     */
42
    public function getResolver()
43
    {
44
        return $this->resolver;
45
    }
46
}