Completed
Pull Request — master (#24)
by
unknown
03:35 queued 01:27
created

ArticleCommand::onNoSuchArticleId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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\MultiLineResponse;
16
use Rvdv\Nntp\Response\Response;
17
18
class ArticleCommand extends Command
19
{
20
    /**
21
     * @var string
22
     */
23
    private $article;
24
25
    /**
26
     * Constructor.
27
     *
28
     * @param string $article The number or msg-id of the article.
29
     */
30 10
    public function __construct($article)
31
    {
32 10
        $this->article = $article;
33
34 10
        parent::__construct([], true);
35 10
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 1
    public function execute()
41
    {
42 1
        return sprintf('ARTICLE %s', $this->article);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 2
    public function getExpectedResponseCodes()
49
    {
50
        return [
51 2
            Response::ARTICLE_FOLLOWS               => 'onArticleFollows',
52 2
            Response::NO_NEWSGROUP_CURRENT_SELECTED => 'onNoNewsGroupCurrentSelected',
53 2
            Response::NO_SUCH_ARTICLE_NUMBER        => 'onNoSuchArticleNumber',
54 2
            Response::NO_SUCH_ARTICLE_ID            => 'onNoSuchArticleId',
55 2
        ];
56
    }
57
58 1
    public function onArticleFollows(MultiLineResponse $response)
59
    {
60 1
        $lines = $response->getLines();
61 1
        $this->result = implode("\r\n", $lines->toArray());
62 1
    }
63
64 1
    public function onNoNewsGroupCurrentSelected(Response $response)
65
    {
66 1
        throw new RuntimeException('A group must be selected first before getting an article.', $response->getStatusCode());
67
    }
68
69 1
    public function onNoSuchArticleNumber(Response $response)
70
    {
71 1
        throw new RuntimeException('No article with that number.', $response->getStatusCode());
72
    }
73
74 1
    public function onNoSuchArticleId(Response $response)
75
    {
76 1
        throw new RuntimeException('No article with that message-id.', $response->getStatusCode());
77
    }
78
}
79