Passed
Push — master ( acba12...b2f89b )
by 世昌
04:15
created

TestConsole::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 15
rs 9.8666
1
<?php
2
3
namespace suda\welcome\console;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputOption;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class TestConsole extends Command
12
{
13
    protected function configure()
14
    {
15
        $this
16
            ->setName('test')
17
            ->setDescription('test someone')
18
            ->addArgument(
19
                'name',
20
                InputArgument::OPTIONAL,
21
                'Who do you want to greet?'
22
            )
23
            ->addOption(
24
                'yell',
25
                null,
26
                InputOption::VALUE_NONE,
27
                'If set, the task will yell in uppercase letters'
28
            );
29
    }
30
31
    protected function execute(InputInterface $input, OutputInterface $output)
32
    {
33
        $name = $input->getArgument('name');
34
        
35
        if (is_string($name)) {
36
            $text = 'Hello ' . $name;
37
        } else {
38
            $text = 'Hello';
39
        }
40
41
        if ($input->getOption('yell')) {
42
            $text = strtoupper($text);
43
        }
44
45
        $output->writeln($text);
46
    }
47
}