GdaemonStatus   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 27
c 2
b 0
f 0
dl 0
loc 56
ccs 19
cts 19
cp 1
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A infoDetails() 0 9 1
A version() 0 7 1
A infoBase() 0 9 1
A request() 0 13 3
1
<?php
2
namespace Knik\Gameap;
3
4
use Knik\Gameap\Exception\GdaemonClientException;
5
6
class GdaemonStatus extends Gdaemon
7
{
8
    const COMMAND_VERSION = 1;
9
    const COMMAND_STATUS_BASE = 2;
10
    const COMMAND_STATUS_DETAILS = 3;
11
12
    /** @var int */
13
    protected $mode = self::DAEMON_SERVER_MODE_STATUS;
14
15
    public function version(): array
16
    {
17
        $results = $this->request(self::COMMAND_VERSION);
18
        
19
        return [
20
            'version' => $results[0] ?? '-',
21
            'compile_date' => $results[1] ?? '-',
22 6
        ];
23
    }
24 6
25
    public function infoBase(): array
26
    {
27 3
        $results = $this->request(self::COMMAND_STATUS_BASE);
28 3
29 1
        return [
30
            'uptime' => $results[0],
31
            'working_tasks_count' => $results[1],
32
            'waiting_tasks_count' => $results[2],
33
            'online_servers_count' => $results[3],
34
        ];
35 3
    }
36
37 3
    public function infoDetails(): array
38
    {
39
        $results = $this->request(self::COMMAND_STATUS_DETAILS);
40 3
41 3
        return [
42 3
            'uptime' => $results[0],
43 3
            'working_tasks_list' => $results[1],
44 1
            'waiting_tasks_list' => $results[2],
45
            'online_servers_list' => $results[3],
46
        ];
47
    }
48
49
    private function request(int $command): array
50 3
    {
51
        $message = $this->binn->serialize([$command]);
52 3
53
        $read = $this->writeAndReadSocket($message);
54
55 3
        $results = $this->binn->unserialize($read);
56 3
57 3
        if ($results[0] != self::STATUS_OK) {
58 3
            throw new GdaemonClientException('Error: ' . isset($results[1]) ? $results[1] : 'Unknown');
59 1
        }
60
        
61
        return array_slice($results, 1);
0 ignored issues
show
Bug introduced by
It seems like $results can also be of type null; however, parameter $array of array_slice() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

61
        return array_slice(/** @scrutinizer ignore-type */ $results, 1);
Loading history...
62
    }
63
}
64