PrivmsgMessage::getUser()   B
last analyzed

Complexity

Conditions 5
Paths 9

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 13
nc 9
nop 0
dl 0
loc 21
rs 8.7624
c 0
b 0
f 0
1
<?php
2
namespace Buttress\IRC\Message;
3
4
class PrivmsgMessage extends GenericMessage
5
{
6
7 View Code Duplication
    public function __construct($prefix, array $params = array(), $connection = null)
0 ignored issues
show
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...
8
    {
9
        $this->command = 'PRIVMSG';
10
        $this->prefix = $prefix;
11
        $this->params = $params;
12
        $this->connection = $connection;
13
    }
14
15
    /**
16
     * @return string
17
     */
18 View Code Duplication
    public function getTo()
0 ignored issues
show
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...
19
    {
20
        if ($params = $this->getParams()) {
21
            return isset($params[0]) ? $params[0] : '';
22
        }
23
        return '';
24
    }
25
26
    /**
27
     * @return string
28
     */
29 View Code Duplication
    public function getMessage()
0 ignored issues
show
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
        if ($params = $this->getParams()) {
32
            return isset($params[1]) ? $params[1] : '';
33
        }
34
        return '';
35
    }
36
37
    /**
38
     * @return string[] [nick, user, host]
39
     */
40
    public function getUser()
41
    {
42
        $nick = "";
43
        $user = "";
44
        $host = "";
45
46
        $matches = array();
47
        if (preg_match('/^(?<nick>[^@!]+)(?:!(?<user>[^@]+)@(?<host>.+))?$/', $this->getPrefix(), $matches)) {
48
            if (isset($matches['nick'])) {
49
                $nick = $matches['nick'];
50
            }
51
            if (isset($matches['user'])) {
52
                $user = $matches['user'];
53
            }
54
            if (isset($matches['host'])) {
55
                $host = $matches['host'];
56
            }
57
        }
58
59
        return array($nick, $user, $host);
60
    }
61
62
}
63