Passed
Pull Request — master (#37)
by Nicolas
02:52
created

MessageAdapterFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 28
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A build() 0 9 1
1
<?php
2
3
namespace Puzzle\AMQP\Workers;
4
5
use Puzzle\AMQP\Messages\BodyFactory;
6
use Puzzle\AMQP\Messages\BodyFactories\Standard;
7
8
class MessageAdapterFactory
9
{
10
    private
11
        $bodyFactory;
12
13 19
    public function __construct(BodyFactory $bodyFactory = null)
14
    {
15 19
        if(! $bodyFactory instanceof BodyFactory)
16 19
        {
17 18
            $bodyFactory = new Standard();
18 18
        }
19
        
20 19
        $this->bodyFactory = $bodyFactory;
21 19
    }
22
    
23
    /**
24
     * @return \Puzzle\AMQP\Workers\MessageAdapter
25
     */
26 19
    public function build(\Swarrot\Broker\Message $message)
27
    {
28 19
        $adapter = new MessageAdapter($message);
29
        
30 19
        $body = $this->bodyFactory->build($adapter->getContentType(), $message->getBody());
31 18
        $adapter->setBody($body);
32
        
33 18
        return $adapter;
34
    }
35
}
36