]> jfr.im git - irc/unrealircd/unrealircd-rpc-php.git/blob - lib/Ban.php
More fixes on return types
[irc/unrealircd/unrealircd-rpc-php.git] / lib / Ban.php
1 <?php
2
3 namespace UnrealIRCd;
4
5 use Exception;
6 use stdClass;
7
8 class Ban implements Contracts\Ban
9 {
10
11 public Connection $connection;
12
13 public function __construct(string $uri, string $api_login, array $options)
14 {
15 $this->connection = new Connection($uri, $api_login, $options);
16 }
17
18 /**
19 * @param string $user
20 * @param string $type
21 * @param array $params
22 * @return stdClass
23 * @throws Exception
24 */
25 public function add(string $user, string $type, array $params): stdClass
26 {
27 $response = $this->connection->query('server_ban.add', [
28 'name' => $params['name'],
29 'type' => $params['type'],
30 'reason' => $params['reason'],
31 'length' => $params['length'] ?? '1d',
32 ]);
33
34 if (is_bool($response)) {
35 return $response;
36 }
37
38 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
39 }
40
41 /**
42 * @param string $user
43 * @param string $type
44 * @param array $params
45 * @return stdClass
46 * @throws Exception
47 */
48 public function delete(string $user, string $type, array $params): stdClass
49 {
50 $response = $this->connection->query('server_ban.del', [
51 'name' => $params['name'],
52 'type' => $params['type'],
53 ]);
54
55 if (is_bool($response)) {
56 return $response;
57 }
58
59 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
60 }
61
62 /**
63 * @return array|bool
64 * @throws Exception
65 */
66 public function get(): stdClass
67 {
68 $response = $this->connection->query('server_ban.list');
69
70 if (!is_bool($response)) {
71 return $response;
72 }
73
74 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
75 }
76
77 /**
78 * @param array $params
79 * @return object|bool
80 * @throws Exception
81 */
82 public function show(array $params): stdClass
83 {
84 $response = $this->connection->query('server_ban.get', [
85 'name' => $params['name'],
86 'type' => $params['type']
87 ]);
88
89 if (!is_bool($response)) {
90 return $response;
91 }
92
93 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
94 }
95 }