Completed
Push — master ( d7e919...298f7d )
by Simonas
64:16
created

ImportCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 16
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 12
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\TranslationsBundle\Command;
13
14
use ONGR\TranslationsBundle\Service\Import\ImportManager;
15
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
16
use Symfony\Component\Console\Input\InputArgument;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Input\InputOption;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
/**
22
 * Translations import command.
23
 */
24
class ImportCommand extends ContainerAwareCommand
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    protected function configure()
30
    {
31
        $this->setName('ongr:translations:import');
32
        $this->setDescription('Import all translations from flat files into the elasticsearch database.');
33
        $this->addOption(
34
            'locales',
35
            'l',
36
            InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
37
            'Import only the specific locales, leave blank to import all configured.'
38
        );
39
        $this->addArgument(
40 6
            'bundle',
41
            InputArgument::OPTIONAL,
42 6
            'Import translations for the specific bundle.'
43 6
        );
44 6
    }
45 6
46 6
    /**
47 6
     * {@inheritdoc}
48 6
     */
49 6
    protected function execute(InputInterface $input, OutputInterface $output)
50 6
    {
51
        /** @var ImportManager $import */
52 6
        $import = $this->getContainer()->get('ongr_translations.import');
53 6
        $configBundles = $this->getContainer()->getParameter('ongr_translations.bundles');
54 6
55 6
        $locales = $input->getOption('locales');
56 6
57 6
        if (empty($locales)) {
58
            $locales = $this->getContainer()->getParameter('ongr_translations.locales');
59 6
        }
60 6
61 6
        $bundleNames = $input->getArgument('bundle');
62 6
63 6
        $import->setLocales($locales);
64
65 6
        if ($bundleNames) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
66
//            $output->writeln("<info>*** Importing {$bundleName} translation files ***</info>");
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
67
//            $bundle = $this->getContainer()->get('kernel')->getBundle($bundleNames);
68
//
69
//            foreach ($bundleNames as $bundleName) {
70 3
//                $dir = $this->getContainer()->get('kernel')->getBundle($bundleName);
71
//                $import->importTranslationFiles($bundle);
72 3
//            }
73 3
        } else {
74
            $output->writeln('<info>*** Importing application translation files ***</info>');
75
            $domain = 'messages';
76 3
            $translations = $import->getTranslationsFromFiles(
77
                $domain,
78 3
                null,
79 3
                [$this->getContainer()->getParameter('kernel.root_dir') . 'translations']
80 2
            );
81
            $import->writeToStorage($domain, $translations);
82 3
            $output->writeln('<info>*** Importing bundles translation files ***</info>');
83
84 3
            foreach ($configBundles as $configBundle) {
85
                $import->importTranslationFiles(
86 3
                    $configBundle,
87 3
                    $this->getContainer()->get('kernel')->locateResource('@'.$configBundle)
88
                );
89 3
            }
90
91
//            $output->writeln('<info>*** Importing component translation files ***</info>');
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
92
//            $import->importBundlesTranslationFiles(
93 3
//                $this->getContainer()->getParameter('ongr_translations.component_directories')
94 2
//            );
95 1
        }
96 1
    }
97
}
98