Completed
Push — master ( f2e7a7...9c404b )
by Victor
01:52
created

TextContent::lastLine()   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 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: victor
5
 * Date: 09/04/16
6
 * Time: 05:01
7
 */
8
9
namespace LazyEight\DiTesto\ValueObject\TextFile;
10
11
12
use LazyEight\BasicTypes\Exceptions\IndexOutOfBoundsException;
13
use LazyEight\BasicTypes\Stringy;
14
use LazyEight\DiTesto\ValueObject\AbstractFileContent;
15
16
class TextContent extends AbstractFileContent
17
{
18
    /*
19
     * @var array
20
     */
21
    private $lines;
22
23
    /**
24
     * @inheritDoc
25
     */
26 1
    public function __construct(Stringy $content, array $lines)
27
    {
28 1
        parent::__construct($content);
29 1
        $this->lines = $lines;
30 1
    }
31
32
    /**
33
     * @return array
34
     */
35 1
    public function getLines()
36
    {
37 1
        return $this->lines;
38
    }
39
40
    /**
41
     * @param int $index
42
     * @throws IndexOutOfBoundsException
43
     * @return Line
44
     */
45
    public function lineAt($index)
46
    {
47
        if (0 > $index || ($this->count() - 1) < $index) {
48
            throw new IndexOutOfBoundsException('The index is negative or not less than the length of the array.');
49
        }
50
        return clone $this->lines[$index];
51
    }
52
53
    /**
54
     * @return Line
55
     */
56
    public function firstLine()
57
    {
58
        return clone $this->lines[0];
59
    }
60
61
    /**
62
     * @return Line
63
     */
64
    public function lastLine()
65
    {
66
        return clone $this->lines[count($this->lines) - 1];
67
    }
68
69
    /**
70
     * @return int
71
     */
72
    public function count()
73
    {
74
        return count($this->lines);
75
    }
76
}
77