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

StatusCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 20.37 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 75.76%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
lcom 1
cbo 6
dl 11
loc 54
ccs 25
cts 33
cp 0.7576
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 11 11 1
B execute() 0 37 6

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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