TextFile::offsetExists()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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