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

Json   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 50
c 0
b 0
f 0
wmc 9
lcom 1
cbo 0
ccs 23
cts 23
cp 1
rs 10

8 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
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;
1 ignored issue
show
Coding Style introduced by
The visibility should be declared for property $jsonAsArray.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
13
    
14 5
    public function __construct($content = [])
15
    {
16 5
        $this->changeContent($content);
17 5
    }
18
    
19 2
    public function inOriginalFormat()
20
    {
21 2
        return $this->jsonAsArray;
22
    }
23
    
24 5
    public function asTransported()
25
    {
26 5
        return json_encode($this->jsonAsArray);
27
    }
28
29 2
    public function getContentType()
30
    {
31 2
        return ContentType::JSON;
32
    }
33
    
34 1
    public function __toString()
35
    {
36 1
        return $this->asTransported();
37
    }
38
    
39 1
    public function footprint()
40
    {
41 1
        return sha1($this->asTransported());
42
    }
43
    
44 5
    public function changeContent($content)
45
    {
46 5
        if(! is_array($content))
47 5
        {
48 1
            $content = array($content);
49 1
        }
50
    
51 5
        $this->jsonAsArray = $content;
52 5
    }
53
    
54 2
    public function changeContentWithJson($json)
55
    {
56 2
        $this->jsonAsArray = json_decode($json, true);
57 2
    }
58
}
59