Messenger::send()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 2
eloc 8
nc 2
nop 2
1
<?php
2
3
namespace gries\Rcon;
4
5
class Messenger
6
{
7
    /**
8
     * @var Connection
9
     */
10
    protected $connection;
11
12
    /**
13
     * @param Connection $connection
14
     */
15
    public function __construct(Connection $connection)
16
    {
17
        $this->connection = $connection;
18
    }
19
20
    /**
21
     * Send text to the server.
22
     *
23
     * @param          $messageText
24
     *
25
     * @param callable $callable
26
     *
27
     * @return string
28
     */
29
    public function send($messageText, callable $callable = null)
30
    {
31
        $message = new Message($messageText);
32
33
        $response = $this->connection
34
            ->sendMessage($message)
35
            ->getBody()
36
        ;
37
38
        if ($callable) {
39
            $response = call_user_func($callable, $response);
40
        }
41
42
        return $response;
43
    }
44
}
45