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

Header::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\Standards\PagSeguro\Types\Filler;
7
use Claudsonm\Pedi\Structure\Field;
8
use Claudsonm\Pedi\Structure\Record;
9
use Claudsonm\Pedi\Structure\Types\Any;
10
use Claudsonm\Pedi\Structure\Types\Numeric;
11
12
class Header extends Record
13
{
14
    private array $definitions = [
15
        [
16
            'size' => 1,
17
            'start' => 1,
18
            'type' => Numeric::class,
19
            'name' => 'TIPO_REGISTRO',
20
        ],
21
        [
22
            'size' => 10,
23
            'start' => 2,
24
            'type' => Numeric::class,
25
            'name' => 'ESTABELECIMENTO',
26
        ],
27
        [
28
            'size' => 8,
29
            'start' => 12,
30
            'type' => Numeric::class,
31
            'name' => 'DATA_PROCESSAMENTO',
32
        ],
33
        [
34
            'size' => 8,
35
            'start' => 20,
36
            'type' => Numeric::class,
37
            'name' => 'DATA_INICIO',
38
        ],
39
        [
40
            'size' => 8,
41
            'start' => 28,
42
            'type' => Numeric::class,
43
            'name' => 'DATA_FIM',
44
        ],
45
        [
46
            'size' => 7,
47
            'start' => 36,
48
            'type' => Numeric::class,
49
            'name' => 'SEQUENCIA_ARQUIVO',
50
        ],
51
        [
52
            'size' => 5,
53
            'start' => 43,
54
            'type' => Any::class,
55
            'name' => 'ADQUIRENTE',
56
        ],
57
        [
58
            'size' => 2,
59
            'start' => 48,
60
            'type' => Numeric::class,
61
            'name' => 'TIPO_EXTRATO',
62
        ],
63
        [
64
            'size' => 21,
65
            'start' => 50,
66
            'type' => Filler::class,
67
            'name' => 'FILLER',
68
        ],
69
        [
70
            'size' => 3,
71
            'start' => 71,
72
            'type' => Any::class,
73
            'name' => 'VERSAO_LAYOUT',
74
        ],
75
        [
76
            'size' => 3,
77
            'start' => 74,
78
            'type' => Any::class,
79
            'name' => 'VERSAO_RELEASE',
80
        ],
81
        [
82
            'size' => 454,
83
            'start' => 77,
84
            'type' => Any::class,
85
            'name' => 'INTERNO_PAGSG',
86
        ],
87
    ];
88
89 45
    public function __construct()
90
    {
91 45
        foreach ($this->definitions as $definition) {
92 45
            $field = (new Field())
93 45
                ->setSize($definition['size'])
94 45
                ->setStart($definition['start'])
95 45
                ->setType(new $definition['type']())
96 45
                ->setName($definition['name']);
97 45
            $this->add($field);
98
        }
99 45
    }
100
101
    /**
102
     * Checa se o conteúdo da linha fornecida indica um registro do tipo header.
103
     */
104 1
    public function matches(string $line): bool
105
    {
106 1
        return TipoRegistro::HEADER === substr($line, 0, 1);
107
    }
108
109
    /**
110
     * Número do estabelecimento. Identificador único do vendedor no PagSeguro.
111
     */
112 1
    public function getEstabelecimento(): int
113
    {
114 1
        return $this->fields[2]->getContent();
115
    }
116
}
117