Passed
Push — master ( 927f67...9bd000 )
by Claudson
06:56
created

Record::getLineNumber()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Claudsonm\Pedi\Structure;
4
5
class Record
6
{
7
    /**
8
     * @var array|Field[]
9
     */
10
    protected array $fields;
11
12
    protected int $length = 0;
13
14
    protected ?int $lineNumber = null;
15
16
    /**
17
     * @return Record
18
     */
19 51
    public function add(Field $field)
20
    {
21 51
        $this->fields[] = $field;
22 51
        $this->length += $field->getSize();
23
24 51
        return $this;
25
    }
26
27 8
    public function getLineContent(): string
28
    {
29 8
        $line = '';
30 8
        foreach ($this->fields as $field) {
31 8
            $line .= $field->getContent();
32
        }
33
34 8
        return $line;
35
    }
36
37 1
    public function getLength(): int
38
    {
39 1
        return $this->length;
40
    }
41
42 48
    public function setLineNumber(?int $number): self
43
    {
44 48
        $this->lineNumber = $number;
45
46 48
        return $this;
47
    }
48
49
    public function getLineNumber(): ?int
50
    {
51
        return $this->lineNumber;
52
    }
53
54 51
    public function parse(string $line): void
55
    {
56 51
        foreach ($this->fields as $field) {
57 51
            $value = substr($line, $field->getStart() - 1, $field->getSize());
58 51
            $field->setContent($value);
59
        }
60 51
    }
61
62 1
    public function matches(string $line): bool
63
    {
64 1
        return $this->getLength() === strlen($line);
65
    }
66
}
67