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

SourcesImporter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 24
ccs 14
cts 15
cp 0.9333
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A import() 0 22 4
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' => ['source' => $source . '/catCFDI.xls', 'importer' => new CfdiCatalogs()],
18 1
            'Nóminas' => ['source' => $source . '/catNomina.xls', 'importer' => new NominaCatalogs()],
19 1
            'CCE' => ['source' => $source, 'importer' => new CceCatalogs()],
20 1
            'Pagos' => ['source' => $source . '/catPagos.xls', 'importer' => new RepCatalogs()],
21
        ];
22
23 1
        foreach ($importers as $name => $info) {
24 1
            $sourceFile = $info['source'];
25 1
            if (! file_exists($sourceFile)) {
26
                throw new RuntimeException("Se esperaba encontrar $sourceFile pero no existe");
27
            }
28
        }
29
30 1
        foreach ($importers as $name => $info) {
31
            /** @var ImporterInterface $importer */
32 1
            $sourceFile = $info['source'];
33 1
            $importer = $info['importer'];
34 1
            $logger->info("Importando $name desde $sourceFile...");
35 1
            $importer->import($sourceFile, $repository, $logger);
36
        }
37 1
    }
38
}
39