Passed
Push — master ( ddf6f5...2e933f )
by Nicolas
03:42 queued 28s
created

Text::append()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
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
use Puzzle\Pieces\StringManipulation;
9
10
class Text implements Body, Footprintable
11
{
12
    use
13
        StringManipulation;
14
15
    private
16
        $content;
17
18 27
    public function __construct($text = '')
19
    {
20 27
        $this->changeText($text);
21 26
    }
22
23 9
    public function inOriginalFormat()
24
    {
25 9
        return $this->content;
26
    }
27
28 22
    public function asTransported()
29
    {
30 22
        return $this->content;
31
    }
32
33 11
    public function getContentType()
34
    {
35 11
        return ContentType::TEXT;
36
    }
37
38 9
    public function __toString()
39
    {
40 9
        return $this->asTransported();
41
    }
42
43 2
    public function footprint()
44
    {
45 2
        return sha1($this->asTransported());
46
    }
47
48 27
    public function changeText($text)
49
    {
50 27
        if(! $this->isConvertibleToString($text))
51 27
        {
52 1
            throw new \LogicException('Body of type Text must be string convertible.');
53
        }
54
55 26
        $this->content = (string) $text;
56 26
    }
57
58 2
    public function append(...$text)
59
    {
60 2
        foreach($text as $part)
61
        {
62 2
            $this->content .= $part;
63 2
        }
64 2
    }
65
66 1
    public function isChunked()
67
    {
68 1
        return false;
69
    }
70
}
71