AuthenticationCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 58
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 4 1
A execute() 0 17 1
1
<?php
2
3
namespace Twitter\Console;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Exception\InvalidArgumentException;
7
use Symfony\Component\Console\Exception\LogicException;
8
use Symfony\Component\Console\Exception\RuntimeException;
9
use Symfony\Component\Console\Helper\QuestionHelper;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
use Symfony\Component\Console\Question\Question;
13
use Twitter\API\Exception\TwitterException;
14
use Twitter\API\REST\TwitterApiGateway;
15
16
/**
17
 * Class AuthenticationCommand
18
 *
19
 * @codeCoverageIgnore
20
 */
21
class AuthenticationCommand extends Command
22
{
23
    /** @var TwitterApiGateway */
24
    private $adapter;
25
26
    /**
27
     * AuthenticationCommand constructor.
28
     *
29
     * @param TwitterApiGateway $adapter
30
     *
31
     * @throws LogicException
32
     */
33
    public function __construct(TwitterApiGateway $adapter, $name = null)
34
    {
35
        parent::__construct($name);
36
37
        $this->adapter = $adapter;
38
    }
39
40
    /**
41
     * Configures the command
42
     */
43
    protected function configure()
44
    {
45
        $this->setDescription('Authenticate');
46
    }
47
48
    /**
49
     * Code executed when command invoked
50
     *
51
     * @param  InputInterface  $input
52
     * @param  OutputInterface $output
53
     *
54
     * @return void
55
     *
56
     * @throws RuntimeException
57
     * @throws LogicException
58
     * @throws InvalidArgumentException
59
     * @throws TwitterException
60
     */
61
    protected function execute(InputInterface $input, OutputInterface $output)
62
    {
63
        $authUrl = $this->adapter->getAuthenticationUrl();
64
65
        /** @var QuestionHelper $helper */
66
        $helper = $this->getHelper('question');
67
        $verificationCode = $helper->ask(
68
            $input,
69
            $output,
70
            new Question('Visit <info>' . $authUrl . '</info> and enter verification code: ')
71
        );
72
73
        $authToken = $this->adapter->getAuthenticationToken($verificationCode);
74
75
        $output->writeln('Token  : <info>' . $authToken->getToken() . '</info>');
76
        $output->writeln('Secret : <info>' . $authToken->getSecret() . '</info>');
77
    }
78
}
79