Total Complexity | 9 |
Total Lines | 60 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
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 | 63 | public function add(Field $field) |
|
20 | { |
||
21 | 63 | $this->fields[] = $field; |
|
22 | 63 | $this->length += $field->getSize(); |
|
23 | |||
24 | 63 | 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 | 2 | public function getLength(): int |
|
38 | { |
||
39 | 2 | return $this->length; |
|
40 | } |
||
41 | |||
42 | 49 | public function setLineNumber(?int $number): self |
|
43 | { |
||
44 | 49 | $this->lineNumber = $number; |
|
45 | |||
46 | 49 | return $this; |
|
47 | } |
||
48 | |||
49 | 43 | public function getLineNumber(): ?int |
|
50 | { |
||
51 | 43 | return $this->lineNumber; |
|
52 | } |
||
53 | |||
54 | 61 | public function parse(string $line): void |
|
55 | { |
||
56 | 61 | foreach ($this->fields as $field) { |
|
57 | 61 | $value = substr($line, $field->getStart() - 1, $field->getSize()); |
|
58 | 61 | $field->setContent($value); |
|
59 | } |
||
60 | 61 | } |
|
61 | |||
62 | 2 | public function matches(string $line): bool |
|
65 | } |
||
66 | } |
||
67 |