PostArticleCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 91.3%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 0
cbo 2
dl 0
loc 72
ccs 21
cts 23
cp 0.913
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A __invoke() 0 17 2
A onArticleReceived() 0 4 1
A onPostingFailed() 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\Response;
16
17
/**
18
 * PostCommand.
19
 *
20
 * @author thebandit
21
 */
22
class PostArticleCommand extends Command implements CommandInterface
23
{
24
    /**
25
     * @var string
26
     */
27
    private $groups;
28
29
    /**
30
     * @var string
31
     */
32
    private $subject;
33
34
    /**
35
     * @var string
36
     */
37
    private $body;
38
39
    /**
40
     * @var string
41
     */
42
    private $from;
43
44
    /**
45
     * @var string
46
     */
47
    private $headers;
48
49
    /**
50
     * Constructor.
51
     */
52 8
    public function __construct($groups, $subject, $body, $from, $headers)
53
    {
54 8
        $this->groups = $groups;
55 8
        $this->subject = $subject;
56 8
        $this->body = $body;
57 8
        $this->from = $from;
58 8
        $this->headers = $headers;
59
60 8
        parent::__construct();
61 8
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 1
    public function __invoke()
67
    {
68
        $article = [
69 1
            'From: '.$this->from,
70 1
            'Newsgroups: '.$this->groups,
71 1
            'Subject: '.$this->subject,
72 1
            'X-poster: php-nntp',
73 1
        ];
74
75 1
        if (null !== $this->headers) {
76
            $article[] = $this->headers;
77
        }
78
79 1
        $article[] = "\r\n".$this->body;
80
81 1
        return implode("\r\n", $article);
82
    }
83
84 1
    public function onArticleReceived(Response $response)
85
    {
86 1
        return $response;
87
    }
88
89 1
    public function onPostingFailed(Response $response)
90
    {
91 1
        throw new RuntimeException(sprintf('Posting failed: %s', $response->getMessage()), $response->getStatusCode());
92
    }
93
}
94