ChannelAdapter::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 4 Features 0
Metric Value
c 5
b 4
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
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