GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 99078a...9605c1 )
by Oanh
02:49
created

AskPasswordGetter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 2
Metric Value
wmc 4
c 3
b 1
f 2
lcom 1
cbo 4
dl 0
loc 66
ccs 19
cts 19
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createQuestionHelper() 0 4 1
A __construct() 0 5 1
A getPassword() 0 10 1
A createLazyGetter() 0 12 1
1
<?php
2
/* (c) Anton Medvedev <[email protected]>
3
 *
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace Deployer\Server\Password;
9
10
use Deployer\Task\Context;
11
use Symfony\Component\Console\Helper\QuestionHelper;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
use Symfony\Component\Console\Question\Question;
15
16
/**
17
 * Ask password getter
18
 *
19
 * @author Vitaliy Zhuk <[email protected]>
20
 */
21
class AskPasswordGetter implements PasswordGetterInterface
22
{
23
    /**
24
     * @var InputInterface
25
     */
26
    private $input;
27
28
    /**
29
     * @var OutputInterface
30
     */
31
    private $output;
32
33
    /**
34
     * Construct
35
     *
36
     * @param InputInterface  $input
37
     * @param OutputInterface $output
38
     */
39 4
    public function __construct(InputInterface $input, OutputInterface $output)
40
    {
41 4
        $this->input = $input;
42 4
        $this->output = $output;
43 4
    }
44
45
    /**
46
     * {@inheritDoc}
47
     */
48 2
    public function getPassword($host, $user)
49
    {
50 2
        $askMessage = sprintf('[%s@%s] Password:', $user, $host);
51
52 2
        $questionHelper = $this->createQuestionHelper();
53 2
        $question = new Question($askMessage);
54 2
        $question->setHidden(true);
55
56 2
        return $questionHelper->ask($this->input, $this->output, $question);
57
    }
58
59
    /**
60
     * Create a lazy ask password getter with use context output and input interfaces
61
     *
62
     * @return CallablePasswordGetter
63
     */
64
    public static function createLazyGetter()
65
    {
66 3
        return new CallablePasswordGetter(function ($host, $user) {
67 1
            $context = Context::get();
68 1
            $output = $context->getOutput();
69 1
            $input = $context->getInput();
70
71 1
            $askPasswordGetter = new AskPasswordGetter($input, $output);
72
73 1
            return $askPasswordGetter->getPassword($host, $user);
74 3
        });
75
    }
76
77
    /**
78
     * Create question helper
79
     *
80
     * @return QuestionHelper
81
     */
82 2
    protected function createQuestionHelper()
83
    {
84 2
        return new QuestionHelper();
85
    }
86
}
87