Passed
Push — master ( ddf6f5...2e933f )
by Nicolas
03:42 queued 28s
created

Json   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 55
ccs 25
cts 25
cp 1
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A inOriginalFormat() 0 4 1
A asTransported() 0 4 1
A getContentType() 0 4 1
A __toString() 0 4 1
A footprint() 0 4 1
A changeContent() 0 9 2
A changeContentWithJson() 0 4 1
A isChunked() 0 4 1
1
<?php
2
3
namespace Puzzle\AMQP\Messages\Bodies;
4
5
use Puzzle\AMQP\Messages\Body;
6
use Puzzle\AMQP\Messages\ContentType;
7
use Puzzle\AMQP\Messages\Footprintable;
8
9
class Json implements Body, Footprintable
10
{
11
    private
12
        $jsonAsArray;
13
14 16
    public function __construct($content = [])
15
    {
16 16
        $this->changeContent($content);
17 16
    }
18
19 6
    public function inOriginalFormat()
20
    {
21 6
        return $this->jsonAsArray;
22
    }
23
24 10
    public function asTransported()
25
    {
26 10
        return \Puzzle\Pieces\Json::encode($this->jsonAsArray);
27
    }
28
29 5
    public function getContentType()
30
    {
31 5
        return ContentType::JSON;
32
    }
33
34 1
    public function __toString()
35
    {
36 1
        return $this->asTransported();
37
    }
38
39 2
    public function footprint()
40
    {
41 2
        return sha1($this->asTransported());
42
    }
43
44 16
    public function changeContent($content)
45
    {
46 16
        if(! is_array($content))
47 16
        {
48 3
            $content = array($content);
49 3
        }
50
51 16
        $this->jsonAsArray = $content;
52 16
    }
53
54 10
    public function changeContentWithJson($json)
55
    {
56 10
        $this->jsonAsArray = \Puzzle\Pieces\Json::decode($json, true);
57 6
    }
58
59 1
    public function isChunked()
60
    {
61 1
        return false;
62
    }
63
}
64