ExportCommand::execute()   B
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 34
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4.7861

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 34
ccs 5
cts 12
cp 0.4167
rs 8.8571
cc 3
eloc 16
nc 2
nop 2
crap 4.7861
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\Export\ExportManager;
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
 * Exports translations.
23
 */
24
class ExportCommand extends ContainerAwareCommand
25
{
26
    /**
27
     * {@inheritdoc}
28 4
     */
29 View Code Duplication
    protected function configure()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30 4
    {
31 4
        $this->setName('ongr:translations:export');
32 4
        $this->setDescription('Export all translations from ES to yaml.');
33 4
        $this->addOption(
34 4
            'locales',
35 4
            'l',
36 4
            InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
37
            'Export only these locales, instead of using the managed locales.'
38 4
        );
39 4
        $this->addOption(
40 4
            'force',
41 4
            'f',
42 4
            InputOption::VALUE_NONE,
43 4
            'If set, the bundle will export all translations, regardless of status'
44
        );
45 4
        $this->addArgument(
46
            'bundle',
47
            InputArgument::OPTIONAL,
48
            'Import translations for the specific bundle.'
49
        );
50 4
    }
51
52
    /**
53 4
     * {@inheritdoc}
54
     */
55 4
    protected function execute(InputInterface $input, OutputInterface $output)
56 4
    {
57 1
        /** @var ExportManager $export */
58
        $export = $this->getContainer()->get('ongr_translations.export');
59
        $bundle = $input->getArgument('bundle');
60 4
61 4
        $locales = $input->getOption('locales', $this->getContainer()->getParameter('ongr_translations.locales'));
0 ignored issues
show
Unused Code introduced by
The call to InputInterface::getOption() has too many arguments starting with $this->getContainer()->g..._translations.locales').

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
62
        $export->setLocales($locales);
63
64
        if ($bundle) {
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...
65
//            $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...
66
//            $bundle = $this->getContainer()->get('kernel')->getBundle($bundleNames);
67
//
68
//            foreach ($bundleNames as $bundleName) {
69
//                $dir = $this->getContainer()->get('kernel')->getBundle($bundleName);
70
//                $import->importTranslationFiles($bundle);
71
//            }
72
        } else {
73
            $export->export(['messages'], $input->getOption('force'));
74
            $export->export($this->getContainer()->getParameter('ongr_translations.bundles'), $input->getOption('force'));
75
        }
76
77
        $prettify = function ($array) {
78
            return !empty($array) ? implode('</comment><info>`, `</info><comment>', $array) : 'all';
79
        };
80
81
        $output->writeln(
82
            sprintf(
83
                '<info>Successfully exported translations in `</info>'
84
                . '<comment>%s</comment><info>` locale(s) for `</info>',
85
                $prettify($locales)
86
            )
87
        );
88
    }
89
}
90