Passed
Push — master ( bc2c58...de2b0e )
by Carlos C
02:23 queued 12s
created

FraccionesArancelarias::shouldRecreateTable()   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
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\SatCatalogosPopulate\Importers\Cce\Injectors;
6
7
use PhpCfdi\SatCatalogosPopulate\AbstractCsvInjector;
8
use PhpCfdi\SatCatalogosPopulate\Database\DataFields;
9
use PhpCfdi\SatCatalogosPopulate\Database\DataTable;
10
use PhpCfdi\SatCatalogosPopulate\Database\DateDataField;
11
use PhpCfdi\SatCatalogosPopulate\Database\PaddingDataField;
12
use PhpCfdi\SatCatalogosPopulate\Database\TextDataField;
13
use PhpCfdi\SatCatalogosPopulate\Utils\ArrayProcessors\RightTrim;
14
use PhpCfdi\SatCatalogosPopulate\Utils\CsvFile;
15
use RuntimeException;
16
17
class FraccionesArancelarias extends AbstractCsvInjector
18
{
19
    /** @param bool $shouldRecreateTable Indicates if the injector must recreate the table */
20 6
    public function __construct(
21
        string $sourceFile,
22
        private bool $shouldRecreateTable
23
    ) {
24 6
        parent::__construct($sourceFile);
25 6
    }
26
27 1
    protected function createCsvFileReader(): CsvFile
28
    {
29 1
        return new CsvFile($this->sourceFile(), new RightTrim());
30
    }
31
32 3
    public function checkHeaders(CsvFile $csv): void
33
    {
34 3
        $csv->move(3);
35 3
        $expected = [
36
            'c_FraccionArancelaria',
37
            'Descripción',
38
            'Fecha de inicio de vigencia',
39
            'Fecha de fin de vigencia',
40
            'UMT',
41
        ];
42 3
        $headers = $csv->readLine();
43
44 3
        if ($expected !== $headers) {
45 1
            throw new RuntimeException("The headers did not match on file {$this->sourceFile()}");
46
        }
47
48 2
        $csv->next();
49 2
    }
50
51 2
    public function dataTable(): DataTable
52
    {
53 2
        return new DataTable('cce_fracciones_arancelarias', new DataFields([
54 2
            new TextDataField('fraccion'),
55 2
            new TextDataField('texto'),
56 2
            new DateDataField('vigencia_desde'),
57 2
            new DateDataField('vigencia_hasta'),
58 2
            new PaddingDataField('unidad', '0', 2),
59
        ]));
60
    }
61
62 1
    protected function shouldRecreateTable(): bool
63
    {
64 1
        return $this->shouldRecreateTable;
65
    }
66
}
67