Passed
Push — master ( 7129da...1959bc )
by Carlos C
13:39 queued 21s
created

SourcesImporter::import()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 32
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 25
CRAP Score 4.0009

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 4
eloc 23
c 3
b 0
f 0
nc 5
nop 3
dl 0
loc 32
ccs 25
cts 26
cp 0.9615
crap 4.0009
rs 9.552
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\SatCatalogosPopulate\Importers;
6
7
use PhpCfdi\SatCatalogosPopulate\Database\Repository;
8
use PhpCfdi\SatCatalogosPopulate\ImporterInterface;
9
use Psr\Log\LoggerInterface;
10
use RuntimeException;
11
12
class SourcesImporter implements ImporterInterface
13
{
14 1
    public function import(string $source, Repository $repository, LoggerInterface $logger): void
15
    {
16 1
        $importers = [
17 1
            'CFDI 3.3' => ['source' => $source . '/catCFDI.xls', 'importer' => new CfdiCatalogs()],
18 1
            'CFDI 4.0' => ['source' => $source . '/cfdi_40.xls', 'importer' => new Cfdi40Catalogs()],
19 1
            'Nóminas' => ['source' => $source . '/catNomina.xls', 'importer' => new NominaCatalogs()],
20 1
            'Nóminas - Estados' => [
21 1
                'source' => $source . '/nominas_estados.xls',
22 1
                'importer' => new NominaEstadosCatalogs(),
23 1
            ],
24 1
            'CCE 1.1' => ['source' => $source, 'importer' => new CceCatalogs()],
25 1
            'CCE 2.0' => ['source' => $source, 'importer' => new Cce20Catalogs()],
26 1
            'Pagos' => ['source' => $source . '/catPagos.xls', 'importer' => new RepCatalogs()],
27 1
            'CCP 2.0' => ['source' => $source . '/CatalogosCartaPorte20.xls', 'importer' => new Ccp20Catalogs()],
28 1
            'CCP 3.0' => ['source' => $source . '/CatalogosCartaPorte30.xls', 'importer' => new Ccp30Catalogs()],
29 1
            'CCP 3.1' => ['source' => $source . '/CatalogosCartaPorte31.xls', 'importer' => new Ccp31Catalogs()],
30 1
            'RET 2.0' => ['source' => $source . '/ret_20.xls', 'importer' => new Ret20Catalogs()],
31 1
        ];
32
33 1
        foreach ($importers as $info) {
34 1
            $sourceFile = $info['source'];
35 1
            if (! file_exists($sourceFile)) {
36
                throw new RuntimeException("Se esperaba encontrar $sourceFile pero no existe");
37
            }
38
        }
39
40 1
        foreach ($importers as $name => $info) {
41
            /** @var ImporterInterface $importer */
42 1
            $sourceFile = $info['source'];
43 1
            $importer = $info['importer'];
44 1
            $logger->info("Importando $name desde $sourceFile...");
45 1
            $importer->import($sourceFile, $repository, $logger);
46
        }
47
    }
48
}
49