Completed
Push — master ( 283da3...5510a0 )
by Tobias
08:02
created

StatusCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 18.37 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
lcom 0
cbo 2
dl 9
loc 49
ccs 0
cts 39
cp 0
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 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
        $this
29
            ->setName('translation:status')
30
            ->setDescription('Show status about your translations.')
31
            ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default')
32
            ->addArgument('locale', InputArgument::OPTIONAL, 'The locale ot use. If omitted, we use all configured locales.', false)
33
            ->addOption('json', null, InputOption::VALUE_NONE, 'If we should output in Json format');
34
    }
35
36
    protected function execute(InputInterface $input, OutputInterface $output)
37
    {
38
        $container = $this->getContainer();
39
        $counter = $storage = $container->get('php_translation.catalogue_counter');
0 ignored issues
show
Unused Code introduced by
$storage is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
40
        $config = $container->get('php_translation.configuration_manager')
41
            ->getConfiguration($input->getArgument('configuration'));
42
43
        $locales = [];
44
        if ($inputLocale = $input->getArgument('locale')) {
45
            $locales = [$inputLocale];
46
        }
47
48
        $catalogues = $container->get('php_translation.catalogue_fetcher')
49
            ->getCatalogues($config, $locales);
50
51
        $stats = [];
52
        foreach ($catalogues as $catalogue) {
53
            $stats[$catalogue->getLocale()] = $counter->getCatalogueStatistics($catalogue);
54
        }
55
56
        if ($input->getOption('json')) {
57
            $output->writeln(json_encode($stats));
58
59
            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