Completed
Pull Request — master (#12)
by Victor
01:54
created

TextFile::getRawContent()   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 4
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 LazyEight\DiTesto;
4
5
use LazyEight\DiTesto\Collections\ArrayObjectLine;
6
use LazyEight\DiTesto\Interfaces\TraversableFileInterface;
7
8
class TextFile extends File implements TraversableFileInterface
9
{
10
    /**
11
     * @var ArrayObjectLine
12
     */
13
    private $lines;
14
15
    /**
16
     * @inheritDoc
17
     */
18
    public function __construct($path, $content = '')
19
    {
20
        parent::__construct($path, $content);
21
        $this->readLines($content);
22
    }
23
24
    /**
25
     * @param string $content
26
     */
27
    private function readLines(string $content)
28
    {
29
        $this->lines = new ArrayObjectLine(array_map(function ($line) {
30
            return new Line($line);
31
        }, explode(PHP_EOL, $content)));
32
    }
33
34
    public function getRawContent(): string
35
    {
36
        return $this->lines->getRawContent();
37
    }
38
39
    public function setRawContent(string $content)
40
    {
41
        parent::setRawContent($content);
42
        $this->readLines($content);
43
    }
44
45
    /**
46
     * @return \ArrayIterator
47
     */
48
    public function getIterator()
49
    {
50
        return $this->lines->getIterator();
51
    }
52
53
    /**
54
     * @param mixed $offset
55
     * @return bool
56
     */
57
    public function offsetExists($offset)
58
    {
59
        return $this->lines->offsetExists($offset);
60
    }
61
62
    /**
63
     * @param mixed $offset
64
     * @return mixed
65
     */
66
    public function offsetGet($offset)
67
    {
68
        return $this->lines->offsetGet($offset);
69
    }
70
71
    /**
72
     * @param mixed $offset
73
     * @param mixed $value
74
     */
75
    public function offsetSet($offset, $value)
76
    {
77
        $this->lines->offsetSet($offset, $value);
78
    }
79
80
    /**
81
     * @param mixed $offset
82
     */
83
    public function offsetUnset($offset)
84
    {
85
        $this->lines->offsetUnset($offset);
86
    }
87
88
    /**
89
     * @return int
90
     */
91
    public function count()
92
    {
93
        return $this->lines->count();
94
    }
95
}
96