Completed
Push — 3.x ( 3e834f...38b337 )
by Grégoire
03:36
created

src/Command/QuestionableCommand.php (2 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Command;
15
16
use Symfony\Component\Console\Command\Command;
17
use Symfony\Component\Console\Helper\QuestionHelper;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
use Symfony\Component\Console\Question\ConfirmationQuestion;
21
use Symfony\Component\Console\Question\Question;
22
23
abstract class QuestionableCommand extends Command
24
{
25
    /**
26
     * @param string   $questionText
27
     * @param mixed    $default
28
     * @param callable $validator
29
     *
30
     * @return mixed
31
     */
32
    final protected function askAndValidate(
33
        InputInterface $input,
34
        OutputInterface $output,
35
        $questionText,
36
        $default,
37
        $validator
38
    ) {
39
        $questionHelper = $this->getQuestionHelper();
40
41
        $question = new Question($questionHelper->getQuestion($questionText, $default), $default);
0 ignored issues
show
The method getQuestion() does not seem to exist on object<Symfony\Component...\Helper\QuestionHelper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
42
43
        $question->setValidator($validator);
44
45
        return $questionHelper->ask($input, $output, $question);
46
    }
47
48
    /**
49
     * @param string $questionText
50
     * @param string $default
51
     * @param string $separator
52
     *
53
     * @return string
54
     */
55
    final protected function askConfirmation(
56
        InputInterface $input,
57
        OutputInterface $output,
58
        $questionText,
59
        $default,
60
        $separator
61
    ) {
62
        $questionHelper = $this->getQuestionHelper();
63
64
        $question = new ConfirmationQuestion($questionHelper->getQuestion(
0 ignored issues
show
The method getQuestion() does not seem to exist on object<Symfony\Component...\Helper\QuestionHelper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65
            $questionText,
66
            $default,
67
            $separator
68
        ), ('no' === $default ? false : true));
69
70
        return $questionHelper->ask($input, $output, $question);
71
    }
72
73
    /**
74
     * @return QuestionHelper
75
     */
76
    final protected function getQuestionHelper()
77
    {
78
        $questionHelper = $this->getHelper('question');
79
80
        if (!$questionHelper instanceof QuestionHelper) {
81
            $questionHelper = new QuestionHelper();
82
            $this->getHelperSet()->set($questionHelper);
83
        }
84
85
        return $questionHelper;
86
    }
87
}
88