Passed
Push — master ( c4ac3e...34bed8 )
by Carlos C
12:17 queued 12s
created

CodigosPostales::checkHeaders()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 40
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 38
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 32
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 40
ccs 38
cts 38
cp 1
crap 3
rs 9.408
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\SatCatalogosPopulate\Importers\Cfdi40\Injectors;
6
7
use Generator;
8
use PhpCfdi\SatCatalogosPopulate\AbstractCsvInjector;
9
use PhpCfdi\SatCatalogosPopulate\Database\BoolDataField;
0 ignored issues
show
Bug introduced by
The type PhpCfdi\SatCatalogosPopu...\Database\BoolDataField was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use PhpCfdi\SatCatalogosPopulate\Database\DataFields;
11
use PhpCfdi\SatCatalogosPopulate\Database\DataTable;
12
use PhpCfdi\SatCatalogosPopulate\Database\DateDataField;
13
use PhpCfdi\SatCatalogosPopulate\Database\TextDataField;
14
use PhpCfdi\SatCatalogosPopulate\Utils\CsvFile;
15
use RuntimeException;
16
17
class CodigosPostales extends AbstractCsvInjector
18
{
19 4
    public function checkHeaders(CsvFile $csv): void
20
    {
21 4
        $csv->move(3);
22 4
        $expectedLines = [
23 4
            [
24 4
                'c_CodigoPostal',
25 4
                'c_Estado',
26 4
                'c_Municipio',
27 4
                'c_Localidad',
28 4
                'Estímulo Franja Fronteriza',
29 4
                'Fecha inicio de vigencia',
30 4
                'Fecha fin de vigencia',
31 4
                'Referencias del Huso Horario',
32 4
            ],
33 4
            [
34 4
                '',
35 4
                '',
36 4
                '',
37 4
                '',
38 4
                '',
39 4
                '',
40 4
                '',
41 4
                'Descripción del Huso Horario',
42 4
                'Mes_Inicio_Horario_Verano',
43 4
                'Día_Inicio_Horario_Verano',
44 4
                'Día_Inicio_Horario_Verano',
45 4
                'Diferencia_Horaria_Verano',
46 4
                'Mes_Inicio_Horario_Invierno',
47 4
                'Día_Inicio_Horario_Invierno',
48 4
                'Día_Inicio_Horario_Invierno',
49 4
                'Diferencia_Horaria_Invierno',
50 4
            ],
51 4
        ];
52 4
        foreach ($expectedLines as $line => $expected) {
53 4
            $line = $line + 1;
54 4
            $headers = array_map(fn ($line): string => trim((string) $line), $csv->readLine());
55 4
            if ($expected !== $headers) {
56 1
                throw new RuntimeException("The headers did not match on file {$this->sourceFile()} line {$line}");
57
            }
58 3
            $csv->next();
59
        }
60
    }
61
62 3
    public function dataTable(): DataTable
63
    {
64 3
        return new DataTable('cfdi_40_codigos_postales', new DataFields([
65 3
            new TextDataField('id'),
66 3
            new TextDataField('estado'),
67 3
            new TextDataField('municipio'),
68 3
            new TextDataField('localidad'),
69 3
            new BoolDataField('estimulo_frontera', ['1']),
70 3
            new DateDataField('vigencia_desde'),
71 3
            new DateDataField('vigencia_hasta'),
72 3
            new TextDataField('huso_descripcion'),
73 3
            new TextDataField('huso_verano_mes_inicio'),
74 3
            new TextDataField('huso_verano_dia_inicio'),
75 3
            new TextDataField('huso_verano_hora_inicio'),
76 3
            new TextDataField('huso_verano_diferencia'),
77 3
            new TextDataField('huso_invierno_mes_inicio'),
78 3
            new TextDataField('huso_invierno_dia_inicio'),
79 3
            new TextDataField('huso_invierno_hora_inicio'),
80 3
            new TextDataField('huso_invierno_diferencia'),
81 3
        ]));
82
    }
83
84
    /** @inheritdoc */
85 2
    protected function readLinesFromCsv(CsvFile $csv): Generator
86
    {
87 2
        foreach ($csv->readLines() as $line) {
88 2
            if ('00000' === $line[0]) {
89
                continue;
90
            }
91
92 2
            yield $line;
93
        }
94
    }
95
}
96