Completed
Push — master ( ad74ba...da4af3 )
by Nicolas
03:26
created

Text   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A format() 0 4 1
A footprint() 0 4 1
A changeText() 0 9 2
A append() 0 11 2
A getContentType() 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
use Puzzle\AMQP\Messages\Footprintable;
8
9
class Text implements Body, Footprintable
10
{
11
    private
12
        $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...
13
    
14 11
    public function __construct($text)
15
    {
16 11
        $this->changeText($text);
17 11
    }
18
    
19 9
    public function format()
20
    {
21 9
        return implode("\n", $this->content);
22
    }
23
    
24 1
    public function footprint()
25
    {
26 1
        return sha1($this->format());
27
    }
28
    
29 11
    public function changeText($text)
30
    {
31 11
        if(! is_array($text))
32 11
        {
33 8
            $text = array($text);
34 8
        }
35
        
36 11
        $this->content = $text;
37 11
    }
38
    
39 2
    public function append($text)
40
    {
41 2
        if(is_array($text))
42 2
        {
43 2
            $this->content = array_merge($this->content, $text);
44
            
45 2
            return;
46
        }
47
        
48 2
        $this->content[] = $text;
49 2
    }
50
51 3
    public function getContentType()
52
    {
53 3
        return ContentType::TEXT;
54
    }
55
    
56 2
    public function __toString()
57
    {
58 2
        return $this->format();
59
    }
60
    
61 1
    public function decode()
62
    {
63 1
        return $this->format();
64
    }
65
}
66