Passed
Pull Request — master (#14)
by Nicolas
02:45
created

BodyFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 92.86%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 31
c 1
b 0
f 0
wmc 5
lcom 0
cbo 7
ccs 13
cts 14
cp 0.9286
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 21 4
1
<?php
2
3
namespace Puzzle\AMQP\Messages;
4
5
use Puzzle\AMQP\Messages\Bodies\Text;
6
use Puzzle\AMQP\Messages\Bodies\Json;
7
use Puzzle\AMQP\Messages\Bodies\Binary;
8
use Puzzle\AMQP\Messages\Bodies\NullBody;
9
use Psr\Log\LoggerAwareTrait;
10
use Psr\Log\NullLogger;
11
12
class BodyFactory
13
{
14
    use LoggerAwareTrait;
15
    
16 21
    public function __construct()
17
    {
18 21
        $this->logger = new NullLogger();
19 21
    }
20
    
21 20
    public function create($contentType, $contentAsTransported)
22
    {
23
        switch($contentType)
24
        {
25 20
            case ContentType::TEXT:
26 6
                return new Text($contentAsTransported);
27
                
28 14
            case ContentType::JSON:
29 1
                $body = new Json();
30 1
                $body->changeContentWithJson($contentAsTransported);
31
                
32 1
                return $body;
33
                
34 13
            case ContentType::BINARY:
35
                return new Binary($contentAsTransported);
36
        }
37
        
38 13
        $this->logger->warning(__CLASS__ . ": unknown content-type, use empty body");
39
        
40 13
        return new NullBody();
41
    }
42
}
43