| 1: | <?php declare(strict_types=1); |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | namespace Clansuite\Capture\Extractor; |
| 14: | |
| 15: | use function get_object_vars; |
| 16: | use function is_array; |
| 17: | use function is_bool; |
| 18: | use function is_int; |
| 19: | use function is_string; |
| 20: | use Clansuite\Capture\ServerInfo; |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | final class ServerInfoExtractor |
| 26: | { |
| 27: | |
| 28: | |
| 29: | |
| 30: | public function extract(object $server): ServerInfo |
| 31: | { |
| 32: | |
| 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: | } |
| 52: | |