Completed
Push — master ( 835ec1...bf73c4 )
by Nikola
02:43
created

ConfigurationDebugCommand   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 93
Duplicated Lines 17.2 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 9
c 1
b 0
f 1
lcom 1
cbo 0
dl 16
loc 93
ccs 0
cts 61
cp 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A configure() 0 7 1
B execute() 0 27 1
A displaySources() 8 8 2
A displayProcessors() 8 8 2
A displayRates() 0 21 2

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
namespace RunOpenCode\Bundle\ExchangeRate\Command;
4
5
use RunOpenCode\ExchangeRate\Configuration;
6
use RunOpenCode\ExchangeRate\Contract\ProcessorsRegistryInterface;
7
use RunOpenCode\ExchangeRate\Contract\RatesConfigurationRegistryInterface;
8
use RunOpenCode\ExchangeRate\Contract\SourcesRegistryInterface;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\Helper\Table;
11
use Symfony\Component\Console\Helper\TableCell;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
class ConfigurationDebugCommand extends Command
16
{
17
    protected $sourcesRegistry;
18
19
    protected $processorsRegistry;
20
21
    protected $ratesConfigurationRegistry;
22
23
    public function __construct(SourcesRegistryInterface $sourcesRegistry, ProcessorsRegistryInterface $processorsRegistry, RatesConfigurationRegistryInterface $ratesConfigurationRegistry)
24
    {
25
        parent::__construct();
26
27
        $this->sourcesRegistry = $sourcesRegistry;
28
        $this->processorsRegistry = $processorsRegistry;
29
        $this->ratesConfigurationRegistry = $ratesConfigurationRegistry;
30
    }
31
32
    protected function configure()
33
    {
34
        $this
35
            ->setName('roc:exchange-rate:configuration-debug')
36
            ->setDescription('Dump current configuration.')
37
        ;
38
    }
39
40
    protected function execute(InputInterface $input, OutputInterface $output)
41
    {
42
        $formatter = $this->getHelper('formatter');
43
44
        $output->writeln($formatter->formatBlock(array(
45
            '-------------------------------------------------------------',
46
            'Displaying current configuration for currency exchange bundle',
47
            '-------------------------------------------------------------'
48
        ), 'info'));
49
50
        $output->writeln('');
51
52
        $this->displaySources($output);
53
54
        $output->writeln('');
55
56
        $this->displayProcessors($output);
57
58
        $output->writeln('');
59
60
        $this->displayRates($output);
61
62
        $output->writeln('');
63
64
        $output->writeln($formatter->formatBlock('-------------------------------------------------------------', 'info'));
65
66
    }
67
68 View Code Duplication
    protected function displaySources(OutputInterface $output)
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...
69
    {
70
        $formatter = $this->getHelper('formatter');
71
72
        foreach ($this->sourcesRegistry as $source) {
73
            $output->writeln($formatter->formatSection('Source', sprintf('%s as %s', get_class($source), $source->getName())));
74
        }
75
    }
76
77 View Code Duplication
    protected function displayProcessors(OutputInterface $output)
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...
78
    {
79
        $formatter = $this->getHelper('formatter');
80
81
        foreach ($this->processorsRegistry as $processor) {
82
            $output->writeln($formatter->formatSection('Processor', get_class($processor)));
83
        }
84
    }
85
86
    protected function displayRates(OutputInterface $output)
87
    {
88
        $table = new Table($output);
89
90
        $table->setHeaders(array(
91
            array(new TableCell('Registered currency rates', array('colspan' => 3))),
92
            array('Currency code', 'Rate type', 'Source')
93
        ));
94
        /**
95
         * @var Configuration $rateConfiguration
96
         */
97
        foreach ($this->ratesConfigurationRegistry as $rateConfiguration) {
98
            $table->addRow(array(
99
                $rateConfiguration->getCurrencyCode(),
100
                $rateConfiguration->getRateType(),
101
                $rateConfiguration->getSource()
102
            ));
103
        }
104
105
        $table->render();
106
    }
107
}
108