From: Bram Matthys Date: Fri, 6 Jan 2023 14:24:17 +0000 (+0100) Subject: Don't use arrays in parameters but use explicit options everwhere. X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-rpc-php.git/commitdiff_plain/92f8fc2fb5ade3dc82eb896c4cf42a5ef8448a7b Don't use arrays in parameters but use explicit options everwhere. For example in ServerBan, from: public function add(string $user, array $params): stdClass; To: public function add(string $name, string $type, string $duration, string $reason): stdClass; As the whole point of having these PHP functions is that it is immediately transparent which things you need to pass. --- diff --git a/lib/Contracts/Contract.php b/lib/Contracts/Contract.php index d79b1e1..bb2b72d 100644 --- a/lib/Contracts/Contract.php +++ b/lib/Contracts/Contract.php @@ -19,5 +19,5 @@ interface Contract * @param array $params * @return stdClass */ - public function get(array $params): stdClass; + //public function get(array $params): stdClass; } diff --git a/lib/Contracts/ServerBan.php b/lib/Contracts/ServerBan.php index e6b8bd3..4cd33e9 100644 --- a/lib/Contracts/ServerBan.php +++ b/lib/Contracts/ServerBan.php @@ -13,12 +13,12 @@ interface ServerBan extends Contract * @param array $params * @return stdClass */ - public function add(string $user, array $params): stdClass; + public function add(string $name, string $type, string $duration, string $reason): stdClass; /** * @param string $user * @param array $params * @return stdClass */ - public function delete(string $user, array $params): stdClass; + public function delete(string $name, string $type): stdClass; } diff --git a/lib/Contracts/User.php b/lib/Contracts/User.php index d008b2c..b835843 100644 --- a/lib/Contracts/User.php +++ b/lib/Contracts/User.php @@ -4,5 +4,4 @@ namespace UnrealIRCd\Contracts; interface User extends Contract { - } diff --git a/lib/ServerBan.php b/lib/ServerBan.php index 46c922f..2a7eaab 100644 --- a/lib/ServerBan.php +++ b/lib/ServerBan.php @@ -19,33 +19,31 @@ class ServerBan implements Contracts\ServerBan * Add a ban. * * @param string $user - * @param array $params * @return stdClass * @throws Exception */ - public function add(string $user, array $params): stdClass + public function add(string $name, string $type, string $duration, string $reason): stdClass { return $this->connection->query('server_ban.add', [ - 'name' => $user, - 'type' => $params['type'], - 'reason' => $params['reason'], - 'duration_string' => $params['length'] ?? '1d', + 'name' => $name, + 'type' => $type, + 'reason' => $reason, + 'duration_string' => $duration ?? '1d', ]); } /** * Delete a ban. * - * @param string $user - * @param array $params + * @param string $name * @return stdClass * @throws Exception */ - public function delete(string $user, array $params): stdClass + public function delete(string $name, string $type): stdClass { return $this->connection->query('server_ban.del', [ - 'name' => $user, - 'type' => $params['type'], + 'name' => $name, + 'type' => $type, ]); } diff --git a/lib/User.php b/lib/User.php index cdabeed..83c93e8 100644 --- a/lib/User.php +++ b/lib/User.php @@ -34,13 +34,12 @@ class User implements Contracts\User /** * Return a user object * - * @param array $params * @return stdClass * @throws Exception */ - public function get(array $params): stdClass + public function get(string $nick): stdClass { - $response = $this->connection->query('user.get', ['nick' => $params['nick']]); + $response = $this->connection->query('user.get', ['nick' => $nick]); if (!is_bool($response)) { return $response;