Messenger::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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