Passed
Push — master ( c55c96...6ef54c )
by Claudson
06:47
created

Saldo::getValor()   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
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Claudsonm\Pedi\Standards\PagSeguro\Records;
4
5
use DateTime;
6
use Claudsonm\Pedi\Standards\PagSeguro\Enums\TipoRegistro;
7
use Claudsonm\Pedi\Structure\Field;
8
use Claudsonm\Pedi\Structure\Record;
9
use Claudsonm\Pedi\Structure\Types\Numeric;
10
11
class Saldo 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' => 10,
22
            'start' => 2,
23
            'type' => Numeric::class,
24
            'name' => 'ESTABELECIMENTO',
25
        ],
26
        [
27
            'size' => 8,
28
            'start' => 12,
29
            'type' => Numeric::class,
30
            'name' => 'DATA_MOVIMENTACAO',
31
        ],
32
        [
33
            'size' => 2,
34
            'start' => 20,
35
            'type' => Numeric::class,
36
            'name' => 'TIPO_EVENTO',
37
        ],
38
        [
39
            'size' => 13,
40
            'start' => 22,
41
            'type' => Numeric::class,
42
            'name' => 'VALOR_SALDO',
43
        ],
44
    ];
45
46 25
    public function __construct()
47
    {
48 25
        foreach ($this->definitions as $definition) {
49 25
            $field = (new Field())
50 25
                ->setSize($definition['size'])
51 25
                ->setStart($definition['start'])
52 25
                ->setType(new $definition['type']())
53 25
                ->setName($definition['name']);
54 25
            $this->add($field);
55
        }
56 25
    }
57
58 23
    public function matches(string $line): bool
59
    {
60 23
        return TipoRegistro::SALDO === substr($line, 0, 1);
61
    }
62
63 1
    public function getDataMovimentacao(): DateTime
64
    {
65 1
        return DateTime::createFromFormat('Ymd', $this->fields[2]->getContent());
66
    }
67
68 1
    public function getValor(): float
69
    {
70 1
        return $this->fields[4]->getContent() / 100;
71
    }
72
}
73