Completed
Push — master ( 1de9b7...830752 )
by Kristof
38:46 queued 24:09
created

ImportTranslationsFromFileCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 5
dl 0
loc 58
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A configure() 0 8 1
A execute() 0 13 2
1
<?php
2
3
namespace Kunstmaan\TranslatorBundle\Command;
4
5
use Kunstmaan\TranslatorBundle\Service\Command\Importer\Importer;
6
use Kunstmaan\TranslatorBundle\Service\Translator\Translator;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Exception\LogicException;
9
use Symfony\Component\Console\Input\InputArgument;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Input\InputOption;
12
use Symfony\Component\Console\Output\OutputInterface;
13
use Symfony\Component\Translation\TranslatorInterface;
14
15
/**
16
 * Class ImportTranslationsFromFileCommand
17
 */
18
final class ImportTranslationsFromFileCommand extends Command
19
{
20
    /** @var Importer */
21
    private $importer;
22
23
    /** @var TranslatorInterface */
24
    private $translator;
25
26
    /** @var array */
27
    private $locales;
28
29
    /**
30
     * ImportTranslationsFromFileCommand constructor.
31
     *
32
     * @param Importer   $importer
33
     * @param Translator $translator
0 ignored issues
show
Documentation introduced by
Should the type for parameter $translator not be TranslatorInterface?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
34
     * @param            $locales
35
     */
36
    public function __construct(Importer $importer, TranslatorInterface $translator, $locales)
37
    {
38
        parent::__construct();
39
        $this->importer = $importer;
40
        $this->translator = $translator;
41
        $this->locales = $locales;
42
    }
43
44
    /**
45
     * Configures this command
46
     */
47
    protected function configure()
48
    {
49
        $this
50
            ->setName('kuma:translator:import-file')
51
            ->setDescription('Import file with translations, supported formats are xlsx, ods, csv')
52
            ->addArgument('file', InputArgument::REQUIRED, 'The full path of the file')
53
            ->addOption('force', 'f', InputOption::VALUE_NONE, 'Force import, overwrite all existing database entries');
54
    }
55
56
    /**
57
     * @throws LogicException
58
     *
59
     * @param InputInterface  $input
60
     * @param OutputInterface $output
61
     */
62
    protected function execute(InputInterface $input, OutputInterface $output)
63
    {
64
        $file = $input->getArgument('file');
65
        $force = $input->getOption('force');
66
67
        $this->importer->importFromSpreadsheet($file, $this->locales, $force);
0 ignored issues
show
Bug introduced by
It seems like $file defined by $input->getArgument('file') on line 64 can also be of type array<integer,string> or null; however, Kunstmaan\TranslatorBund...importFromSpreadsheet() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
68
        if ($force) {
69
            $confirmation = $this->translator->trans('kuma_translator.command.import.flash.force_success');
70
        } else {
71
            $confirmation = $this->translator->trans('kuma_translator.command.import.flash.success');
72
        }
73
        $output->writeln($confirmation);
74
    }
75
}
76