Passed
Push — master ( 08379c...c55c96 )
by Claudson
07:14
created

Trailer::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 9
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Claudsonm\Pedi\Standards\PagSeguro\Records;
4
5
use Claudsonm\Pedi\Standards\PagSeguro\Enums\TipoRegistro;
6
use Claudsonm\Pedi\Structure\Field;
7
use Claudsonm\Pedi\Structure\Record;
8
use Claudsonm\Pedi\Structure\Types\Any;
9
use Claudsonm\Pedi\Structure\Types\Numeric;
10
11
class Trailer extends Record
12
{
13
    private array $definitions = [
14
        [
15
            'size' => 1,
16
            'start' => 1,
17
            'type' => Numeric::class,
18
            'name' => 'TIPO_REGISTRO',
19
        ],
20
        [
21
            'size' => 11,
22
            'start' => 2,
23
            'type' => Numeric::class,
24
            'name' => 'QUANTIDADE_REGISTROS',
25
        ],
26
        [
27
            'size' => 518,
28
            'start' => 13,
29
            'type' => Any::class,
30
            'name' => 'INTERNO_PAGSG',
31
        ],
32
    ];
33
34 44
    public function __construct()
35
    {
36 44
        foreach ($this->definitions as $definition) {
37 44
            $field = (new Field())
38 44
                ->setSize($definition['size'])
39 44
                ->setStart($definition['start'])
40 44
                ->setType(new $definition['type']())
41 44
                ->setName($definition['name']);
42 44
            $this->add($field);
43
        }
44 44
    }
45
46 1
    public function matches(string $line): bool
47
    {
48 1
        return TipoRegistro::TRAILER === substr($line, 0, 1);
49
    }
50
}
51