Completed
Push — master ( 4f66c7...b30e53 )
by Victor
02:00
created

TextContent   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 33.33%

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 8
c 3
b 1
f 1
lcom 1
cbo 2
dl 0
loc 61
ccs 2
cts 6
cp 0.3333
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getLines() 0 4 1
A lineAt() 0 7 3
A firstLine() 0 4 1
A lastLine() 0 4 1
A count() 0 4 1
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
    public function __construct(Stringy $content, array $lines)
27
    {
28
        parent::__construct($content);
29
        $this->lines = $lines;
30
    }
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