Completed
Push — master ( 52893e...3452a0 )
by
unknown
27:00 queued 11:58
created

helpers.php ➔ tail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 9.4285
1
<?php
2
declare(strict_types=1);
3
4
use Spires\Core\Core;
5
use Spires\Irc\Client;
6
use Spires\Plugins\Message\Inbound\Message as InboundMessage;
7
use Spires\Plugins\Message\Outbound\Message;
8
use Spires\Plugins\SystemMessage\Outbound\SystemMessage;
9
10
function core(string $abstract = null, array $parameters = [])
11
{
12
    if (is_null($abstract)) {
13
        return Core::getInstance();
14
    }
15
16
    return Core::getInstance()->make($abstract, $parameters);
17
}
18
19
function send_command(string $command, string $params)
20
{
21
    core(Client::class)->write((string) new SystemMessage($command, $params));
22
}
23
24
function send_to(array $targets, string $text)
25
{
26
    core(Client::class)->write((string) new Message($targets, $text));
27
}
28
29
function reply(string $text)
30
{
31
    $myNick = core(Client::class)->user()->nickname();
32
    $senderNick = core(InboundMessage::class)->nickname();
33
    $targets = core(InboundMessage::class)->targets();
34
    $targets = array_map(function ($target) use ($myNick, $senderNick) {
35
        return $target === $myNick ? $senderNick : $target;
36
    }, $targets);
37
38
    send_to($targets, $text);
39
}
40
41
/**
42
 * Returns the first element of the given array
43
 *
44
 * @param array $array
45
 * @return mixed
46
 */
47
function head($array)
48
{
49
    return array_values($array)[0];
50
}
51
52
/**
53
 * Returns everything but the head of the array
54
 * 
55
 * @param array $array
56
 * @return mixed
57
 */
58
function tail($array)
59
{
60
    array_shift($array);
61
    return $array;
62
}
63