GenericMessage::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 4
dl 7
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Buttress\IRC\Message;
3
4
use Buttress\IRC\Connection\ConnectionInterface;
5
6
class GenericMessage implements MessageInterface
7
{
8
9
    /**
10
     * @var array
11
     */
12
    protected $params;
13
14
    /**
15
     * @var String
16
     */
17
    protected $command;
18
19
    /**
20
     * @var String
21
     */
22
    protected $prefix;
23
24
    /**
25
     * @var ConnectionInterface
26
     */
27
    protected $connection;
28
29 View Code Duplication
    function __construct($command, $prefix = "", array $params = array(), $connection = null)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
    {
31
        $this->command = $command;
32
        $this->connection = $connection;
33
        $this->params = $params;
34
        $this->prefix = $prefix;
35
    }
36
37
    /**
38
     * @return ConnectionInterface
39
     */
40
    public function getConnection()
41
    {
42
        return $this->connection;
43
    }
44
45
    /**
46
     * @param ConnectionInterface $connection
47
     * @return void
48
     */
49
    public function setConnection(ConnectionInterface $connection)
50
    {
51
        $this->connection = $connection;
52
    }
53
54
    public function getRaw()
55
    {
56
        $command = strtoupper($this->getCommand());
57
58
        if ($prefix = $this->getPrefix()) {
59
            $raw = ":{$prefix} {$command}";
60
        } else {
61
            $raw = $this->getCommand();
62
        }
63
64
        if ($params = $this->getParams()) {
65
            $last = array_pop($params);
66
67
            $param_string = implode(' ', $params);
68
            if ($param_string) {
69
                $raw .= " {$param_string}";
70
            }
71
            $raw .= " :{$last}";
72
        }
73
74
        return $raw;
75
    }
76
77
    /**
78
     * @return string
79
     */
80
    public function getCommand()
81
    {
82
        return $this->command;
83
    }
84
85
    /**
86
     * @return string
87
     */
88
    public function getPrefix()
89
    {
90
        return $this->prefix;
91
    }
92
93
    /**
94
     * @param string $prefix
95
     * @return void
96
     */
97
    public function setPrefix($prefix)
98
    {
99
        $this->prefix = $prefix;
100
    }
101
102
    /**
103
     * @return array
104
     */
105
    public function getParams()
106
    {
107
        return $this->params;
108
    }
109
110
}
111