Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ServerInfoExtractor
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
14
100.00% covered (success)
100.00%
1 / 1
 extract
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
14
1<?php declare(strict_types=1);
2
3/**
4 * Clansuite Server Query
5 *
6 * SPDX-FileCopyrightText: 2003-2025 Jens A. Koch
7 * SPDX-License-Identifier: MIT
8 *
9 * For the full copyright and license information, please view
10 * the LICENSE file that was distributed with this source code.
11 */
12
13namespace Clansuite\Capture\Extractor;
14
15use function get_object_vars;
16use function is_array;
17use function is_bool;
18use function is_int;
19use function is_string;
20use Clansuite\Capture\ServerInfo;
21
22/**
23 * Extracts server information from a query result into a structured ServerInfo object.
24 */
25final class ServerInfoExtractor
26{
27    /**
28     * extract method.
29     */
30    public function extract(object $server): ServerInfo
31    {
32        /** @var array<string, mixed> $data */
33        $data = get_object_vars($server);
34
35        return new ServerInfo(
36            address: is_string($data['address'] ?? null) ? $data['address'] : null,
37            queryport: is_int($data['queryport'] ?? null) ? $data['queryport'] : null,
38            online: is_bool($data['online'] ?? null) ? $data['online'] : false,
39            gamename: is_string($data['gamename'] ?? null) ? $data['gamename'] : null,
40            gameversion: is_string($data['gameversion'] ?? null) ? $data['gameversion'] : null,
41            servertitle: is_string($data['servertitle'] ?? null) ? $data['servertitle'] : null,
42            mapname: is_string($data['mapname'] ?? null) ? $data['mapname'] : null,
43            gametype: is_string($data['gametype'] ?? null) ? $data['gametype'] : null,
44            numplayers: is_int($data['numplayers'] ?? null) ? $data['numplayers'] : 0,
45            maxplayers: is_int($data['maxplayers'] ?? null) ? $data['maxplayers'] : 0,
46            rules: is_array($data['rules'] ?? null) ? $data['rules'] : [],
47            players: is_array($data['players'] ?? null) ? $data['players'] : [],
48            errstr: is_string($data['errstr'] ?? null) ? $data['errstr'] : null,
49        );
50    }
51}