These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the NNTP library. |
||
5 | * |
||
6 | * (c) Robin van der Vleuten <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace Rvdv\Nntp\Command; |
||
13 | |||
14 | use Rvdv\Nntp\Exception\RuntimeException; |
||
15 | use Rvdv\Nntp\Response\Response; |
||
16 | |||
17 | /** |
||
18 | * AuthInfoCommand |
||
19 | * |
||
20 | * @author Robin van der Vleuten <[email protected]> |
||
21 | */ |
||
22 | class AuthInfoCommand extends Command implements CommandInterface |
||
23 | { |
||
24 | const AUTHINFO_USER = 'USER'; |
||
25 | const AUTHINFO_PASS = 'PASS'; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | private $type; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | private $value; |
||
36 | |||
37 | 15 | public function __construct($type, $value) |
|
38 | { |
||
39 | 15 | $this->type = $type; |
|
40 | 15 | $this->value = $value; |
|
41 | |||
42 | 15 | parent::__construct(); |
|
43 | 15 | } |
|
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | */ |
||
48 | 1 | public function execute() |
|
49 | { |
||
50 | 1 | return sprintf('AUTHINFO %s %s', $this->type, $this->value); |
|
51 | } |
||
52 | |||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | */ |
||
56 | 2 | public function getExpectedResponseCodes() |
|
57 | { |
||
58 | return array( |
||
59 | 2 | Response::AUTHENTICATION_ACCEPTED => 'onAuthenticationAccepted', |
|
60 | 2 | Response::PASSWORD_REQUIRED => 'onPasswordRequired', |
|
61 | 2 | Response::AUTHENTICATION_REJECTED => 'onAuthenticationRejected', |
|
62 | 2 | Response::AUTHENTICATION_OUTOFSEQUENCE => 'onAuthenticationOutOfSequence', |
|
63 | 2 | ); |
|
64 | } |
||
65 | |||
66 | 1 | public function onAuthenticationAccepted(Response $response) |
|
67 | { |
||
68 | 1 | return; |
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
69 | } |
||
70 | |||
71 | 1 | public function onPasswordRequired(Response $response) |
|
72 | { |
||
73 | 1 | return; |
|
0 ignored issues
–
show
|
|||
74 | } |
||
75 | |||
76 | 1 | public function onAuthenticationRejected(Response $response) |
|
77 | { |
||
78 | 1 | throw new RuntimeException(sprintf('Authentication failed with given value for type %s', $this->type)); |
|
79 | } |
||
80 | |||
81 | 1 | public function onAuthenticationOutOfSequence(Response $response) |
|
82 | { |
||
83 | 1 | throw new RuntimeException(sprintf('Authentication is out of sequence for type %s', $this->type)); |
|
84 | } |
||
85 | } |
||
86 |