Completed
Push — master ( 9bb610...8aa334 )
by Robin
01:44
created

src/Command/PostArticleCommand.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 5
   public function __construct($groups, $subject, $body, $from, $headers)
53
   {
54 5
       $this->groups = $groups;
55 5
       $this->subject = $subject;
56 5
       $this->body = $body;
57 5
       $this->from = $from;
58 5
       $this->headers = $headers;
59
60 5
       parent::__construct();
61 5
   }
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 ($this->headers !== null) {
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)
0 ignored issues
show
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...
85
    {
86 1
    }
87
88 1
    public function onPostingFailed(Response $response)
89
    {
90 1
        throw new RuntimeException(sprintf('Posting failed: %s', $response->getMessage()), $response->getStatusCode());
91
    }
92
}
93