Completed
Pull Request — master (#9)
by Nicolas
03:08
created

Json::footprint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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 3
    public function __construct($content = [])
15
    {
16 3
        $this->changeContent($content);
17 3
    }
18
    
19 3
    public function format()
20
    {
21 3
        return json_encode($this->jsonAsArray);
22
    }
23
    
24
    public function footprint()
25
    {
26
        return sha1($this->format());
27
    }
28
29
    public function getContentType()
30
    {
31
        return ContentType::JSON;
32
    }
33
    
34 3
    public function changeContent($content)
35
    {
36 3
        if(! is_array($content))
37 3
        {
38 1
            $content = array($content);
39 1
        }
40
    
41 3
        $this->jsonAsArray = $content;
42 3
    }
43
    
44 2
    public function changeContentWithJson($json)
45
    {
46 2
        $this->jsonAsArray = json_decode($json, true);
47 2
    }
48
    
49 1
    public function __toString()
50
    {
51 1
        return $this->format();
52
    }
53
    
54 1
    public function decode()
55
    {
56 1
        return $this->jsonAsArray;
57
    }
58
}
59