ShowConsole   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 12 1
A configure() 0 17 1
A __construct() 0 3 1
1
<?php
2
3
/**
4
 * This file is part of byrokrat\giroapp.
5
 *
6
 * byrokrat\giroapp is free software: you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License as published
8
 * by the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * byrokrat\giroapp is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with byrokrat\giroapp. If not, see <http://www.gnu.org/licenses/>.
18
 *
19
 * Copyright 2016-21 Hannes Forsgård
20
 */
21
22
declare(strict_types=1);
23
24
namespace byrokrat\giroapp\Console;
25
26
use byrokrat\giroapp\Formatter\FormatterCollection;
27
use Symfony\Component\Console\Command\Command;
28
use Symfony\Component\Console\Input\InputOption;
29
use Symfony\Component\Console\Input\InputInterface;
30
use Symfony\Component\Console\Output\OutputInterface;
31
32
/**
33
 * Display information on individual donors
34
 */
35
final class ShowConsole implements ConsoleInterface
36
{
37
    use Helper\DonorArgument;
38
39
    /**
40
     * @var FormatterCollection
41
     */
42
    private $formatterCollection;
43
44
    public function __construct(FormatterCollection $formatterCollection)
45
    {
46
        $this->formatterCollection = $formatterCollection;
47
    }
48
49
    public function configure(Command $command): void
50
    {
51
        $command->setName('show');
52
        $command->setDescription('Display donor information');
53
        $command->setHelp('Display information on individual donors');
54
55
        $this->configureDonorArgument($command);
56
57
        $command->addOption(
58
            'format',
59
            null,
60
            InputOption::VALUE_REQUIRED,
61
            sprintf(
62
                'Set output format, possible values: %s',
63
                implode(", ", $this->formatterCollection->getItemKeys())
64
            ),
65
            'human'
66
        );
67
    }
68
69
    public function execute(InputInterface $input, OutputInterface $output): void
70
    {
71
        /** @var string */
72
        $formatId = $input->getOption('format');
73
74
        $formatter = $this->formatterCollection->getFormatter($formatId);
75
76
        $formatter->initialize($output);
77
78
        $formatter->formatDonor($this->readDonor($input));
79
80
        $formatter->finalize();
81
    }
82
}
83