ServiceActivator::doReply()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 4 Features 0
Metric Value
c 4
b 4
f 0
dl 0
loc 10
rs 9.4285
cc 3
eloc 7
nc 4
nop 1
1
<?php
2
3
namespace PEIP\ABS\Service;
4
5
/*
6
 * This file is part of the PEIP package.
7
 * (c) 2009-2011 Timo Michna <timomichna/yahoo.de>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
/*
14
 * PEIP\ABS\Service\ServiceActivator
15
 * Abstract base class for all service activators
16
 *
17
 * @author Timo Michna <timomichna/yahoo.de>
18
 * @package PEIP
19
 * @subpackage service
20
 * @extends \PEIP\Pipe\Pipe
21
 * @implements \PEIP\INF\Event\Connectable, \PEIP\INF\Channel\SubscribableChannel, \PEIP\INF\Channel\Channel, \PEIP\INF\Handler\Handler, \PEIP\INF\Message\MessageBuilder
22
 */
23
24
25
abstract class ServiceActivator extends \PEIP\Pipe\Pipe
26
{
27
    protected $serviceCallable;
28
29
    /**
30
     * Handles the reply logic.
31
     * Delegates calling of service to method 'callService'.
32
     * Replies on message�s reply-channel or registered output-channel if set.
33
     *
34
     * @param \PEIP\INF\Message\Message $message message to handle/reply for
35
     *
36
     * @return
37
     */
38
    public function doReply(\PEIP\INF\Message\Message $message)
39
    {
40
        $res = $this->callService($message);
41
        $out = (bool) $message->hasHeader('REPLY_CHANNEL')
42
            ? $message->getHeader('REPLY_CHANNEL')
43
            : $this->outputChannel;
44
        if ($out) {
45
            $this->replyMessage($res, $res);
0 ignored issues
show
Unused Code introduced by
The call to ServiceActivator::replyMessage() has too many arguments starting with $res.

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.

Loading history...
46
        }
47
    }
48
49
    /**
50
     * Calls a method on a service (registered as a callable) with
51
     * content/payload of given message as argument.
52
     *
53
     * @param \PEIP\INF\Message\Message $message message to call the service with it�s content/payload
54
     *
55
     * @return mixed result of calling the registered service callable with message content/payload
56
     */
57 View Code Duplication
    protected function callService(\PEIP\INF\Message\Message $message)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
    {
59
        $res = null;
60
        if (is_callable($this->serviceCallable)) {
61
            $res = call_user_func($this->serviceCallable, $message->getContent());
62
        } else {
63
            if (is_object($this->serviceCallable) && method_exists($this->serviceCallable, 'handle')) {
64
                $res = $this->serviceCallable->handle($message->getContent());
65
            }
66
        }
67
68
        return $res;
69
    }
70
}
71