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

Trailer::matches()   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 1
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 43
    public function __construct()
35
    {
36 43
        foreach ($this->definitions as $definition) {
37 43
            $field = (new Field())
38 43
                ->setSize($definition['size'])
39 43
                ->setStart($definition['start'])
40 43
                ->setType(new $definition['type']())
41 43
                ->setName($definition['name']);
42 43
            $this->add($field);
43
        }
44 43
    }
45
46
    public function matches(string $line): bool
47
    {
48
        return TipoRegistro::TRAILER === substr($line, 0, 1);
49
    }
50
}
51