Completed
Push — master ( 378e2f...604c4b )
by Robin
01:27
created

HeadCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 50
ccs 14
cts 14
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A onHeadFollows() 0 4 1
A __construct() 0 6 1
A __invoke() 0 4 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
 * HeadCommand.
20
 *
21
 * @author elabz
22
 */
23
class HeadCommand extends Command implements CommandInterface
24
{
25
    /**
26
     * @var string
27
     */
28
    private $article;
29
30
    /**
31
     * Constructor.
32
     *
33
     * @param string $article
34
     */
35 8
    public function __construct($article)
36
    {
37 8
        $this->article = $article;
38
39 8
        parent::__construct(true);
40 8
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 1
    public function __invoke()
46
    {
47 1
        return sprintf('HEAD %s', $this->article);
48
    }
49
50
    /**
51
     * @return string
52
     */
53 1
    public function onHeadFollows(MultiLineResponse $response)
54
    {
55 1
        return implode("\r\n", $response->getLines());
56
    }
57
58 1
    public function onNoNewsGroupCurrentSelected(Response $response)
59
    {
60 1
        throw new RuntimeException('A group must be selected first before getting an article header.', $response->getStatusCode());
61
    }
62
63 1
    public function onNoSuchArticleNumber(Response $response)
64
    {
65 1
        throw new RuntimeException('No article with that number.', $response->getStatusCode());
66
    }
67
68 1
    public function onNoSuchArticleId(Response $response)
69
    {
70 1
        throw new RuntimeException('No article with that message-id.', $response->getStatusCode());
71
    }
72
}
73