Completed
Push — feature/improved-response-hand... ( d991be )
by Robin
03:26
created

PostArticleCommand::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2.024

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
ccs 9
cts 11
cp 0.8182
rs 9.4285
cc 2
eloc 10
nc 2
nop 0
crap 2.024
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 6
   public function __construct($groups, $subject, $body, $from, $headers)
53
   {
54 6
       $this->groups = $groups;
55 6
       $this->subject = $subject;
56 6
       $this->body = $body;
57 6
       $this->from = $from;
58 6
       $this->headers = $headers;
59
60 6
       parent::__construct([]);
61 6
   }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 1
    public function __invoke()
67
    {
68 1
        $article = 'From: '.$this->from."\r\n";
69 1
        $article .= 'Newsgroups: '.$this->groups."\r\n";
70 1
        $article .= 'Subject: '.$this->subject."\r\n";
71 1
        $article .= "X-poster: php-nntp\r\n";
72 1
        if ($this->headers !== null) {
73
            $article .= $this->headers."\r\n";
74
        }
75 1
        $article .= "\r\n";
76 1
        $article .= $this->body;
77
78 1
        return $article;
79
    }
80
81 1
    public function onArticleReceived(Response $response)
0 ignored issues
show
Unused Code introduced by
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
82
    {
83 1
        return true;
84
    }
85
86 1
    public function onPostingFailed(Response $response)
87
    {
88 1
        throw new RuntimeException(sprintf('Posting failed: %s', $response->getMessage()), $response->getStatusCode());
89
    }
90
}
91