Passed
Push — dev ( 1930e5...4afce3 )
by 世昌
02:32
created

TestConsole::execute()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 14
rs 10
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
        if ($name) {
35
            $text = 'Hello ' . $name;
0 ignored issues
show
Bug introduced by
Are you sure $name of type string|string[] can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
            $text = 'Hello ' . /** @scrutinizer ignore-type */ $name;
Loading history...
36
        } else {
37
            $text = 'Hello';
38
        }
39
40
        if ($input->getOption('yell')) {
41
            $text = strtoupper($text);
42
        }
43
44
        $output->writeln($text);
45
    }
46
}