DescriptionQuestion   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 78.56%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 35
ccs 11
cts 14
cp 0.7856
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 14 2
A buildValidator() 0 9 2
1
<?php
2
namespace Samurai\Project\Question;
3
4
use Samurai\Task\ITask;
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
use Symfony\Component\Console\Question\Question as SimpleQuestion;
8
9
/**
10
 * Class DescriptionQuestion
11
 * @package Samurai\Project\Question
12
 * @author Raphaël Lefebvre <[email protected]>
13
 */
14
class DescriptionQuestion extends Question
15
{
16
    /**
17
     * @param InputInterface $input
18
     * @param OutputInterface $output
19
     * @return int
20
     */
21 4
    public function execute(InputInterface $input, OutputInterface $output)
22
    {
23 4
        $question = new SimpleQuestion('<question>Enter your project description:</question>');
24 4
        $question->setValidator($this->buildValidator());
25 4
        $question->setMaxAttempts(3);
26
27 4
        $this->getProject()->setDescription($this->ask(
28 4
            $input,
29 4
            $output,
30
            $question
31 4
        ));
32
33 4
        return $this->getProject()->getDescription() ? ITask::NO_ERROR_CODE : ITask::BLOCKING_ERROR_CODE;
34
    }
35
36
    /**
37
     * @return callable
38
     */
39
    private function buildValidator()
40
    {
41 4
        return function ($answer) {
42
            if(!$answer){
43
                throw new \RuntimeException('Error: description is required');
44
            }
45
            return $answer;
46 4
        };
47
    }
48
}
49