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

Trailer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
wmc 3
eloc 22
dl 0
loc 38
ccs 9
cts 11
cp 0.8182
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A matches() 0 3 1
A __construct() 0 9 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