HeaderServiceActivator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 28.21 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 6
Bugs 5 Features 0
Metric Value
wmc 5
c 6
b 5
f 0
lcom 1
cbo 2
dl 11
loc 39
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A callService() 11 13 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace PEIP\Service;
4
5
/*
6
 * To change this template, choose Tools | Templates
7
 * and open the template in the editor.
8
 */
9
10
/**
11
 * Description of HeaderServiceActivator.
12
 *
13
 * @author timo
14
 */
15
class HeaderServiceActivator extends \PEIP\Service\ServiceActivator
16
{
17
    protected $headerName;
18
19
    /**
20
     * @param $serviceCallable
21
     * @param $inputChannel
22
     * @param $outputChannel
23
     *
24
     * @return
25
     */
26
    public function __construct($serviceCallable, $headerName, \PEIP\INF\Channel\Channel $inputChannel = null, \PEIP\INF\Channel\Channel $outputChannel = null)
27
    {
28
        $this->headerName = $headerName;
29
        parent::__construct($serviceCallable, $inputChannel, $outputChannel);
30
    }
31
32
    /**
33
     * Calls a method on a service (registered as a callable) with
34
     * content/payload of given message as argument.
35
     *
36
     * @param \PEIP\INF\Message\Message $message message to call the service with it�s content/payload
37
     *
38
     * @return mixed result of calling the registered service callable with message content/payload
39
     */
40 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...
41
    {
42
        $res = null;
43
        if (is_callable($this->serviceCallable)) {
44
            $res = call_user_func($this->serviceCallable, $message->getHeader($this->headerName));
45
        } else {
46
            if (is_object($this->serviceCallable) && method_exists($this->serviceCallable, 'handle')) {
47
                $res = $this->serviceCallable->handle($message->getHeader($this->headerName));
48
            }
49
        }
50
51
        return $res;
52
    }
53
}
54