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

Saldo::matches()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
crap 1
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 1
    public function __construct()
46
    {
47 1
        foreach ($this->definitions as $definition) {
48 1
            $field = (new Field())
49 1
                ->setSize($definition['size'])
50 1
                ->setStart($definition['start'])
51 1
                ->setType(new $definition['type']())
52 1
                ->setName($definition['name']);
53 1
            $this->add($field);
54
        }
55 1
    }
56
57 1
    public function matches(string $line): bool
58
    {
59 1
        return TipoRegistro::SALDO === substr($line, 0, 1);
60
    }
61
}
62