ChannelAdapter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 5
Bugs 4 Features 0
Metric Value
wmc 5
c 5
b 4
f 0
lcom 1
cbo 1
dl 0
loc 29
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getMessage() 0 8 2
A handle() 0 8 2
1
<?php
2
3
namespace PEIP\Channel;
4
5
class ChannelAdapter
6
{
7
    protected $channel;
8
    protected $handler;
9
10
    public function __construct(\PEIP\ABS\Handler\MessageHandler $handler, $channel)
11
    {
12
        $this->channel = $channel;
13
        $this->handler = $handler;
14
    }
15
16
    protected function getMessage($object)
17
    {
18
        if ($this->channel instanceof \PEIP\INF\Channel\SubscribableChannel) {
19
            return $object;
20
        } else {
21
            return $object->getContent()->receive();
22
        }
23
    }
24
25
    public function handle($object)
26
    {
27
        $message = $this->getMessage($object);
28
        if (!is_object($message)) {
29
            throw new \Exception('Could not get Message from Channel');
30
        }
31
        $this->handler->handle($message);
32
    }
33
}
34