Completed
Push — master ( 79674b...df23e0 )
by Robin
9s
created

ArticleCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 2
cbo 3
dl 0
loc 61
ccs 22
cts 22
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A execute() 0 4 1
A getExpectedResponseCodes() 0 9 1
A onArticleFollows() 0 5 1
A onNoNewsGroupCurrentSelected() 0 4 1
A onNoSuchArticleNumber() 0 4 1
A onNoSuchArticleId() 0 4 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
/**
19
 * BodyCommand.
20
 *
21
 * @author thebandit
22
 */
23
class ArticleCommand extends Command
24
{
25
    /**
26
     * @var string
27
     */
28
    private $article;
29
30
    /**
31
     * Constructor.
32
     *
33
     * @param string $article The number or msg-id of the article.
34
     */
35 10
    public function __construct($article)
36
    {
37 10
        $this->article = $article;
38
39 10
        parent::__construct([], true);
40 10
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 1
    public function execute()
46
    {
47 1
        return sprintf('ARTICLE %s', $this->article);
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 2
    public function getExpectedResponseCodes()
54
    {
55
        return [
56 2
            Response::ARTICLE_FOLLOWS               => 'onArticleFollows',
57 2
            Response::NO_NEWSGROUP_CURRENT_SELECTED => 'onNoNewsGroupCurrentSelected',
58 2
            Response::NO_SUCH_ARTICLE_NUMBER        => 'onNoSuchArticleNumber',
59 2
            Response::NO_SUCH_ARTICLE_ID            => 'onNoSuchArticleId',
60 2
        ];
61
    }
62
63 1
    public function onArticleFollows(MultiLineResponse $response)
64
    {
65 1
        $lines = $response->getLines();
66 1
        $this->result = implode("\r\n", $lines->toArray());
67 1
    }
68
69 1
    public function onNoNewsGroupCurrentSelected(Response $response)
70
    {
71 1
        throw new RuntimeException('A group must be selected first before getting an article.', $response->getStatusCode());
72
    }
73
74 1
    public function onNoSuchArticleNumber(Response $response)
75
    {
76 1
        throw new RuntimeException('No article with that number.', $response->getStatusCode());
77
    }
78
79 1
    public function onNoSuchArticleId(Response $response)
80
    {
81 1
        throw new RuntimeException('No article with that message-id.', $response->getStatusCode());
82
    }
83
}
84