SuiteChooser::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
namespace Bex\Behat\ChooseTestsExtension\Chooser;
4
5
use Bex\Behat\ChooseTestsExtension\Chooser\BaseChooser;
6
use Symfony\Component\Console\Helper\QuestionHelper;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\Console\Question\ChoiceQuestion;
10
11
class SuiteChooser extends BaseChooser
12
{
13
    /**
14
     * @var string[]
15
     */
16
    private $suiteNames;
17
    
18
    /**
19
     * @param InputInterface  $input
20
     * @param OutputInterface $output
21
     * @param array           $suiteConfigurations
22
     */
23
    public function __construct(InputInterface $input, OutputInterface $output, array $suiteConfigurations = [])
24
    {
25
        parent::__construct($input, $output);
26
27
        $this->suiteNames = array_keys($suiteConfigurations);
0 ignored issues
show
Documentation Bug introduced by
It seems like array_keys($suiteConfigurations) of type array<integer,integer|string> is incompatible with the declared type array<integer,string> of property $suiteNames.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
28
    }
29
    
30
    public function execute()
31
    {
32
        if ($this->shouldAskQuestion()) {
33
            $answer = $this->askQuestion('Choose suite:', array_merge(['All'], $this->suiteNames), 'All');
34
35
            if ($answer !== 'All') {
36
                $this->input->setOption('suite', $answer);
37
            }
38
        }
39
    }
40
41
    private function shouldAskQuestion()
42
    {
43
        $selectedSuite = $this->input->getOption('suite');
44
        $numberOfSuites = count($this->suiteNames);
45
46
        return empty($selectedSuite) && ($numberOfSuites > 1);
47
    }
48
}
49