Passed
Push — master ( d1ccc3...a5920b )
by Nicolas
04:01
created

Standard   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 8
dl 0
loc 41
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A initializeFactories() 0 8 1
A handleContentType() 0 6 1
A build() 0 11 2
1
<?php
2
3
namespace Puzzle\AMQP\Messages\BodyFactories;
4
5
use Psr\Log\LoggerAwareTrait;
6
use Psr\Log\NullLogger;
7
use Puzzle\AMQP\Messages\TypedBodyFactories;
8
use Puzzle\AMQP\Messages\BodyFactory;
9
use Puzzle\AMQP\Messages\ContentType;
10
use Puzzle\AMQP\Messages\Bodies\NullBody;
11
use Puzzle\AMQP\Messages\TypedBodyFactory;
12
13
class Standard implements BodyFactory
14
{
15
    use LoggerAwareTrait;
16
    
17
    private
18
        $factories;
19
    
20 33
    public function __construct()
21
    {
22 33
        $this->logger = new NullLogger();
23 33
        $this->initializeFactories();
24 33
    }
25
    
26 33
    private function initializeFactories()
27
    {
28 33
        $this->factories = [
29 33
            ContentType::TEXT => new TypedBodyFactories\Text(),
30 33
            ContentType::JSON => new TypedBodyFactories\Json(),
31 33
            ContentType::BINARY => new TypedBodyFactories\Binary(),
32
        ];
33 33
    }
34
    
35 2
    public function handleContentType($contentType, TypedBodyFactory $factory)
36
    {
37 2
        $this->factories[$contentType] = $factory;
38
        
39 2
        return $this;
40
    }
41
    
42 24
    public function build($contentType, $contentAsTransported)
43
    {
44 24
        if(isset($this->factories[$contentType]))
45 24
        {
46 19
            return $this->factories[$contentType]->build($contentAsTransported);
47
        }
48
        
49 6
        $this->logger->warning(__CLASS__ . ": unknown content-type, use empty body");
50
        
51 6
        return new NullBody();
52
    }
53
}
54