RelationAwareCommand::configureRequiredArguments()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
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\InputArgument;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
/**
18
 * RelationAwareCommand
19
 *
20
 * Base class for generator commands.
21
 *
22
 * @abstract
23
 * @package   Cli
24
 * @copyright 2014 - 2015 Grégoire HUBERT
25
 * @author    Grégoire HUBERT
26
 * @license   X11 {@link http://opensource.org/licenses/mit-license.php}
27
 * @see       PommAwareCommand
28
 */
29
abstract class RelationAwareCommand extends SchemaAwareCommand
30
{
31
    protected $relation;
32
33
    /**
34
     * configure
35
     *
36
     * @see PommAwareCommand
37
     */
38
    protected function configureRequiredArguments()
39
    {
40
        parent::configureRequiredArguments()
41
            ->addArgument(
42
                'relation',
43
                InputArgument::REQUIRED,
44
                'Relation to inspect.'
45
            )
46
            ;
47
48
        return $this;
49
    }
50
51
    /**
52
     * execute
53
     *
54
     * @see Command
55
     */
56
    protected function execute(InputInterface $input, OutputInterface $output)
57
    {
58
        parent::execute($input, $output);
59
        $this->relation = $input->getArgument('relation');
60
    }
61
62
    /**
63
     * updateOutput
64
     *
65
     * Add ModelManager output lines to the CLI output.
66
     *
67
     * @access protected
68
     * @param  OutputInterface  $output
69
     * @param  array            $lines
70
     * @return RelationAwareCommand
71
     */
72
    protected function updateOutput(OutputInterface $output, array $lines = [])
73
    {
74
        foreach ($lines as $line) {
75
            $status = $line["status"] == "ok" ? "<fg=green>✓</fg=green>" : "<fg=red>✗</fg=red>";
76
77
            switch ($line['operation']) {
78
                case "creating":
79
                    $operation = sprintf("<fg=green>%s</fg=green>", ucwords($line['operation']));
80
                    break;
81
                case "overwriting":
82
                    $operation = sprintf("<fg=cyan>%s</fg=cyan>", ucwords($line['operation']));
83
                    break;
84
                case "deleting":
85
                    $operation = sprintf("<fg=red>%s</fg=red>", ucwords($line['operation']));
86
                    break;
87
                default:
88
                    $operation = ucwords($line['operation']);
89
            }
90
91
            $output->writeln(
92
                sprintf(
93
                    " %s  %s file <fg=yellow>'%s'</fg=yellow>.",
94
                    $status,
95
                    $operation,
96
                    $line['file']
97
                )
98
            );
99
        }
100
101
        return $this;
102
    }
103
}
104