InspectConfig::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of Pomm's Cli package.
4
 *
5
 * (c) 2014 - 2015 Grégoire HUBERT <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PommProject\Cli\Command;
11
12
use Symfony\Component\Console\Command\Command;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Output\OutputInterface;
15
16
/**
17
 * InspectConfig
18
 *
19
 * Display information about session builders.
20
 *
21
 * @package   Cli
22
 * @copyright 2014 - 2015 Grégoire HUBERT
23
 * @author    Grégoire HUBERT
24
 * @license   X11 {@link http://opensource.org/licenses/mit-license.php}
25
 * @see       SchemaAwareCommand
26
 */
27
class InspectConfig extends PommAwareCommand
28
{
29
    /**
30
     * configure
31
     *
32
     * @see command
33
     */
34
    protected function configure()
35
    {
36
        $this
37
            ->setName("pomm:inspect:config")
38
            ->setDescription("Show session builders name.")
39
            ;
40
41
        parent::configure();
42
    }
43
44
    /**
45
     * execute
46
     *
47
     * Set pomm dependent variables.
48
     *
49
     * @see Command
50
     */
51
    protected function execute(InputInterface $input, OutputInterface $output)
52
    {
53
        parent::execute($input, $output);
54
55
        $results = array_keys($this->getPomm()->getSessionBuilders());
56
        switch (count($results)) {
57
            case 0:
58
                $output->writeln("There are no session builders in current Pomm instance.");
59
                break;
60
            case 1:
61
                $output->writeln("There is <info>1</info> builder in current Pomm instance:");
62
                $this->showResultList($output, $results);
63
                break;
64
            default:
65
                $output->writeln(sprintf("There are <info>%d</info> builders in current Pomm instance:", count($results)));
66
                $this->showResultList($output, $results);
67
        }
68
69
        return 0;
70
    }
71
72
    /**
73
     * showResultList
74
     *
75
     * Add list of builders to output.
76
     *
77
     * @access private
78
     * @param  OutputInterface  $output
79
     * @param  array            $results
80
     * @return InspectConfig    $this
81
     */
82
    private function showResultList(OutputInterface $output, array $results)
83
    {
84
        foreach ($results as $name) {
85
            $output->writeln(
86
                sprintf(
87
                    " → '%s'%s",
88
                    $name,
89
                    $this->getPomm()->isDefaultSession($name)
90
                        ? '(default)'
91
                        : ''
92
                )
93
            );
94
        }
95
96
        return $this;
97
    }
98
}
99