Completed
Push — master ( 396a44...7d840c )
by Tobias
11:02
created

StatusCommand::execute()   B

Complexity

Conditions 6
Paths 16

Size

Total Lines 37
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 7.1796

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 37
ccs 17
cts 25
cp 0.68
rs 8.439
c 1
b 0
f 0
cc 6
eloc 24
nc 16
nop 2
crap 7.1796
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[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 Translation\Bundle\Command;
13
14
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
15
use Symfony\Component\Console\Input\InputArgument;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Input\InputOption;
18
use Symfony\Component\Console\Output\OutputInterface;
19
use Symfony\Component\Console\Style\SymfonyStyle;
20
21
/**
22
 * @author Tobias Nyholm <[email protected]>
23
 */
24
class StatusCommand extends ContainerAwareCommand
25
{
26
    use BundleTrait;
27
28 1 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...
29
    {
30
        $this
31 1
            ->setName('translation:status')
32 1
            ->setDescription('Show status about your translations.')
33 1
            ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default')
34 1
            ->addArgument('locale', InputArgument::OPTIONAL, 'The locale ot use. If omitted, we use all configured locales.', false)
35 1
            ->addOption('json', null, InputOption::VALUE_NONE, 'If we should output in Json format')
36 1
            ->addOption('bundle', 'b', InputOption::VALUE_REQUIRED, 'The translations for bundle you want to check.')
37
        ;
38 1
    }
39
40 1
    protected function execute(InputInterface $input, OutputInterface $output)
41
    {
42 1
        $container = $this->getContainer();
43 1
        $counter = $container->get('php_translation.catalogue_counter');
44 1
        $config = $container->get('php_translation.configuration_manager')
45 1
            ->getConfiguration($input->getArgument('configuration'));
46 1
        $this->configureBundleDirs($input, $config);
47
48 1
        $locales = [];
49 1
        if ($inputLocale = $input->getArgument('locale')) {
50 1
            $locales = [$inputLocale];
51
        }
52
53 1
        $catalogues = $container->get('php_translation.catalogue_fetcher')
54 1
            ->getCatalogues($config, $locales);
55
56 1
        $stats = [];
57 1
        foreach ($catalogues as $catalogue) {
58 1
            $stats[$catalogue->getLocale()] = $counter->getCatalogueStatistics($catalogue);
59
        }
60
61 1
        if ($input->getOption('json')) {
62 1
            $output->writeln(json_encode($stats));
63
64 1
            return;
65
        }
66
67
        $io = new SymfonyStyle($input, $output);
68
        foreach ($stats as $locale => $stat) {
69
            $rows = [];
70
            foreach ($stat as $domain => $data) {
71
                $rows[] = [$domain, $data['defined'], $data['new'], $data['obsolete']];
72
            }
73
            $io->title('Locale: '.$locale);
74
            $io->table(['Domain', 'Defined', 'New', 'Obsolete'], $rows);
75
        }
76
    }
77
}
78