Completed
Push — master ( 4e8bc9...f46df8 )
by Tobias
13:01 queued 05:03
created

StatusCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 18.37 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 72.21%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
lcom 1
cbo 5
dl 9
loc 49
ccs 26
cts 36
cp 0.7221
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 9 9 1
B execute() 0 36 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 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...
27
    {
28 1
        $this
29 1
            ->setName('translation:status')
30 1
            ->setDescription('Show status about your translations.')
31 1
            ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default')
32 1
            ->addArgument('locale', InputArgument::OPTIONAL, 'The locale ot use. If omitted, we use all configured locales.', false)
33 1
            ->addOption('json', null, InputOption::VALUE_NONE, 'If we should output in Json format');
34 1
    }
35
36 1
    protected function execute(InputInterface $input, OutputInterface $output)
37
    {
38 1
        $container = $this->getContainer();
39 1
        $counter = $container->get('php_translation.catalogue_counter');
40 1
        $config = $container->get('php_translation.configuration_manager')
41 1
            ->getConfiguration($input->getArgument('configuration'));
42
43 1
        $locales = [];
44 1
        if ($inputLocale = $input->getArgument('locale')) {
45 1
            $locales = [$inputLocale];
46 1
        }
47
48 1
        $catalogues = $container->get('php_translation.catalogue_fetcher')
49 1
            ->getCatalogues($config, $locales);
50
51 1
        $stats = [];
52 1
        foreach ($catalogues as $catalogue) {
53 1
            $stats[$catalogue->getLocale()] = $counter->getCatalogueStatistics($catalogue);
54 1
        }
55
56 1
        if ($input->getOption('json')) {
57 1
            $output->writeln(json_encode($stats));
58
59 1
            return;
60
        }
61
62
        $io = new SymfonyStyle($input, $output);
63
        foreach ($stats as $locale => $stat) {
64
            $rows = [];
65
            foreach ($stat as $domain => $data) {
66
                $rows[] = [$domain, $data['defined'], $data['new'], $data['obsolete']];
67
            }
68
            $io->title('Locale: '.$locale);
69
            $io->table(['Domain', 'Defined', 'New', 'Obsolete'], $rows);
70
        }
71
    }
72
}
73