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

CceCatalogs   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 95%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 34
ccs 19
cts 20
cp 0.95
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A import() 0 9 5
A createImporters() 0 14 1
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 CceCatalogs implements ImporterInterface
13
{
14
    /**
15
     * @param string $source Folder where all files exist
16
     */
17 1
    public function import(string $source, Repository $repository, LoggerInterface $logger): void
18
    {
19 1
        $importers = $this->createImporters();
20 1
        foreach ($importers as $file => $importer) {
21 1
            $sourceFile = $source . '/' . $file;
22 1
            if (! file_exists($sourceFile) || is_dir($sourceFile) || ! is_readable($sourceFile)) {
23
                throw new RuntimeException("No se encontró el archivo $sourceFile");
24
            }
25 1
            $importer->import($sourceFile, $repository, $logger);
26
        }
27 1
    }
28
29
    /**
30
     * @return ImporterInterface[]
31
     */
32 2
    public function createImporters(): array
33
    {
34
        return [
35 2
            'c_ClavePedimento.xls' => new Cce\CceClavePedimento(),
36 2
            'c_Colonia.xls' => new Cce\CceColonia(),
37 2
            'C_Estado.xls' => new Cce\CceEstado(),
38 2
            'c_FraccionArancelaria.xls' => new Cce\CceFraccionArancelaria(true),
39 2
            'c_FraccionArancelaria_2021.xls' => new Cce\CceFraccionArancelaria(false),
40 2
            'c_INCOTERM.xls' => new Cce\CceIncoterm(),
41 2
            'c_Localidad.xls' => new Cce\CceLocalidad(),
42 2
            'c_MotivoTraslado.xls' => new Cce\CceMotivoTraslado(),
43 2
            'c_Municipio.xls' => new Cce\CceMunicipio(),
44 2
            'c_TipoOperacion.xls' => new Cce\CceTipoOperacion(),
45 2
            'c_UnidadAduana.xls' => new Cce\CceUnidadAduana(),
46
        ];
47
    }
48
}
49