Completed
Pull Request — master (#169)
by Mikołaj
05:25
created

ImportFromCsvCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
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