Completed
Pull Request — master (#18)
by
unknown
02:00
created

PostArticleCommand::getExpectedResponseCodes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 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(array());
61 8
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 1
    public function execute()
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
    /**
82
     * {@inheritdoc}
83
     */
84 2
    public function getExpectedResponseCodes()
85
    {
86
        return array(
87 2
            Response::ARTICLE_RECEIVED => 'onArticleReceived',
88 2
            Response::POSTING_FAILED => 'onPostingFailed',
89 2
        );
90
    }
91
    
92 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...
93
    {
94 1
    	return true;
95
    }
96
97 1
    public function onPostingFailed(Response $response)
98
    {
99 1
        throw new RuntimeException(sprintf('Posting failed: %s', $response->getMessage()), $response->getStatusCode());
100
    }
101
}
102