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

Saldo::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 9
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
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\Numeric;
9
10
class Saldo extends Record
11
{
12
    private array $definitions = [
13
        [
14
            'size' => 1,
15
            'start' => 1,
16
            'type' => Numeric::class,
17
            'name' => 'TIPO_REGISTRO',
18
        ],
19
        [
20
            'size' => 10,
21
            'start' => 2,
22
            'type' => Numeric::class,
23
            'name' => 'ESTABELECIMENTO',
24
        ],
25
        [
26
            'size' => 8,
27
            'start' => 12,
28
            'type' => Numeric::class,
29
            'name' => 'DATA_MOVIMENTACAO',
30
        ],
31
        [
32
            'size' => 2,
33
            'start' => 20,
34
            'type' => Numeric::class,
35
            'name' => 'TIPO_EVENTO',
36
        ],
37
        [
38
            'size' => 13,
39
            'start' => 22,
40
            'type' => Numeric::class,
41
            'name' => 'VALOR_SALDO',
42
        ],
43
    ];
44
45
    public function __construct()
46
    {
47
        foreach ($this->definitions as $definition) {
48
            $field = (new Field())
49
                ->setSize($definition['size'])
50
                ->setStart($definition['start'])
51
                ->setType(new $definition['type']())
52
                ->setName($definition['name']);
53
            $this->add($field);
54
        }
55
    }
56
57
    public function matches(string $line): bool
58
    {
59
        return TipoRegistro::SALDO === substr($line, 0, 1);
60
    }
61
}
62