| 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 | 66 | public function add(Field $field) |
|
| 20 | { |
||
| 21 | 66 | $this->fields[] = $field; |
|
| 22 | 66 | $this->length += $field->getSize(); |
|
| 23 | |||
| 24 | 66 | 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 | 50 | public function setLineNumber(?int $number): self |
|
| 43 | { |
||
| 44 | 50 | $this->lineNumber = $number; |
|
| 45 | |||
| 46 | 50 | return $this; |
|
| 47 | } |
||
| 48 | |||
| 49 | 44 | public function getLineNumber(): ?int |
|
| 50 | { |
||
| 51 | 44 | return $this->lineNumber; |
|
| 52 | } |
||
| 53 | |||
| 54 | 64 | public function parse(string $line): void |
|
| 55 | { |
||
| 56 | 64 | foreach ($this->fields as $field) { |
|
| 57 | 64 | $value = substr($line, $field->getStart() - 1, $field->getSize()); |
|
| 58 | 64 | $field->setContent($value); |
|
| 59 | } |
||
| 60 | 64 | } |
|
| 61 | |||
| 62 | 2 | public function matches(string $line): bool |
|
| 65 | } |
||
| 66 | } |
||
| 67 |