These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 |
||
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
|
|||
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 |
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:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.