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

Text::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 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 Text implements Body
9
{
10
    private
11
        $content;
1 ignored issue
show
Coding Style introduced by
The visibility should be declared for property $content.

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 8
    public function __construct($text)
14
    {
15 8
        $this->changeText($text);
16 8
    }
17
    
18 8
    public function format()
19
    {
20 8
        return implode("\n", $this->content);
21
    }
22
    
23 3
    public function footprint()
24
    {
25 3
        return sha1($this->format());
26
    }
27
    
28 8
    public function changeText($text)
29
    {
30 8
        if(! is_array($text))
31 8
        {
32 5
            $text = array($text);
33 5
        }
34
        
35 8
        $this->content = $text;
36 8
    }
37
    
38 2
    public function append($text)
39
    {
40 2
        if(is_array($text))
41 2
        {
42 2
            $this->content = array_merge($this->content, $text);
43
            
44 2
            return;
45
        }
46
        
47 2
        $this->content[] = $text;
48 2
    }
49
50 3
    public function getContentType()
51
    {
52 3
        return ContentType::TEXT;
53
    }
54
    
55
    public function __toString()
56
    {
57
        return $this->format();
58
    }
59
    
60 1
    public function decode()
61
    {
62 1
        return $this->format();
63
    }
64
}
65