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

ConfigurationDebugCommand::displayRates()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 21
ccs 0
cts 16
cp 0
rs 9.3143
cc 2
eloc 11
nc 2
nop 1
crap 6
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