Completed
Push — master ( 0c8701...84a040 )
by Julien
13s
created

ChoiceQuestion::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 5
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace TheAentMachine\Helper;
4
5
use Symfony\Component\Console\Helper\QuestionHelper;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
/**
10
 * A helper class to easily create choice questions.
11
 */
12
class ChoiceQuestion extends BaseQuestion
13
{
14
    /** @var string[] */
15
    private $choices;
16
17
    public function __construct(QuestionHelper $helper, InputInterface $input, OutputInterface $output, string $question, array $choices)
18
    {
19
        parent::__construct($helper, $input, $output, $question);
20
        $this->choices = $choices;
21
    }
22
23
    /**
24
     * @return string
25
     */
26
    public function askSingleChoiceQuestion() : string
27
    {
28
        $question = new \Symfony\Component\Console\Question\ChoiceQuestion($this->question, $this->choices);
29
        return $this->helper->ask($this->input, $this->output, $question);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->helper->as...his->output, $question) could return the type null|boolean which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
30
    }
31
32
    /**
33
     * @return string[]
34
     */
35
    public function askMultipleChoiceQuestion() : array
36
    {
37
        $question = new \Symfony\Component\Console\Question\ChoiceQuestion($this->question, $this->choices);
38
        $question->setMultiselect(true);
39
        return $this->helper->ask($this->input, $this->output, $question);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->helper->as...his->output, $question) could return the type null|string|boolean which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
40
    }
41
}
42