Completed
Push — master ( cf353c...bbc3bb )
by Mikołaj
11s
created

ImportFromCsvCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 31
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 10 1
A execute() 0 7 1
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusCmsPlugin\Command;
14
15
use BitBag\SyliusCmsPlugin\Processor\ImportProcessorInterface;
16
use Symfony\Component\Console\Command\Command;
17
use Symfony\Component\Console\Input\InputArgument;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
final class ImportFromCsvCommand extends Command
22
{
23
    /** @var ImportProcessorInterface */
24
    private $importProcessor;
25
26
    public function __construct(ImportProcessorInterface $importProcessor)
27
    {
28
        parent::__construct();
29
30
        $this->importProcessor = $importProcessor;
31
    }
32
33
    protected function configure(): void
34
    {
35
        $this
36
            ->setName('bitbag:import:csv')
37
            ->setDescription('Imports a resource')
38
            ->setHelp('This command allows you to import resources from CSV. It takes file path and resource name as parameter.')
39
            ->addArgument('resource', InputArgument::REQUIRED, 'Importer resource name.')
40
            ->addArgument('file', InputArgument::REQUIRED, 'CSV file path.')
41
        ;
42
    }
43
44
    protected function execute(InputInterface $input, OutputInterface $output): void
45
    {
46
        $resourceName = $input->getArgument('resource');
47
        $file = $input->getArgument('file');
48
49
        $this->importProcessor->process($resourceName, $file);
50
    }
51
}
52