]> jfr.im git - irc/unrealircd/unrealircd-rpc-php.git/commitdiff
Don't use arrays in parameters but use explicit options everwhere.
authorBram Matthys <redacted>
Fri, 6 Jan 2023 14:24:17 +0000 (15:24 +0100)
committerBram Matthys <redacted>
Fri, 6 Jan 2023 14:24:17 +0000 (15:24 +0100)
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.

lib/Contracts/Contract.php
lib/Contracts/ServerBan.php
lib/Contracts/User.php
lib/ServerBan.php
lib/User.php

index d79b1e14151bc3b4bfa6a16ffcb7406d19c9b007..bb2b72d9b8cec696ee2d780c9e119e3dd6d5bc51 100644 (file)
@@ -19,5 +19,5 @@ interface Contract
      * @param  array  $params
      * @return stdClass
      */
-    public function get(array $params): stdClass;
+    //public function get(array $params): stdClass;
 }
index e6b8bd340445c436aee2ab51a67db79f09bedeb8..4cd33e92864633736b5a42dd940d60ffdd1bdaee 100644 (file)
@@ -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;
 }
index d008b2c2953f9a08be986765d2f6e8cc5c1d2056..b8358434dde3db10a2424af5ad238c46a65f4c4b 100644 (file)
@@ -4,5 +4,4 @@ namespace UnrealIRCd\Contracts;
 
 interface User extends Contract
 {
-
 }
index 46c922f5d81fcf84e5402a0ddbc429e2aeeb64bc..2a7eaabbc84e7ebdc35d96ba68972ba0f0941c80 100644 (file)
@@ -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,
         ]);
     }
 
index cdabeedf334e104fd898aca3bc2575f55f45ebdd..83c93e82d549f59abff0a16f61673eb393ca8ec9 100644 (file)
@@ -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;