Test Failed
Pull Request — master (#9)
by Nicolas
06:10
created

Json   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A format() 0 4 1
A footprint() 0 4 1
A getContentType() 0 4 1
A changeContent() 0 9 2
A changeContentWithJson() 0 4 1
A __toString() 0 4 1
A decode() 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
8
class Json implements Body
9
{
10
    private
11
        $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...
12
    
13
    public function __construct($content = [])
14
    {
15
        $this->changeContent($content);
16
    }
17
    
18
    public function format()
19
    {
20
        return json_encode($this->jsonAsArray);
21
    }
22
    
23
    public function footprint()
24
    {
25
        return sha1($this->format());
26
    }
27
28
    public function getContentType()
29
    {
30
        return ContentType::JSON;
31
    }
32
    
33
    public function changeContent($content)
34
    {
35
        if(! is_array($content))
36
        {
37
            $content = array($content);
38
        }
39
    
40
        $this->jsonAsArray = $content;
41
    }
42
    
43
    public function changeContentWithJson($json)
44
    {
45
        $this->jsonAsArray = json_decode($json, true);
46
    }
47
    
48
    public function __toString()
49
    {
50
        return $this->format();
51
    }
52
    
53
    public function decode()
54
    {
55
        return $this->jsonAsArray;
56
    }
57
}
58