Skip to content

Commit d41f483

Browse files
Add type safety and PHP 8.4 supported
1 parent 719a744 commit d41f483

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

src/Exceptions.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
declare(strict_types=1);
3+
namespace Supabase;
4+
5+
class Exception{
6+
public static function Error()
7+
{
8+
throw new Exception('Error');
9+
}
10+
};

src/Functions.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace Supabase;
35
use Supabase\Supabase;
46

57
class Functions extends Supabase
68
{
7-
public function getAllData($table=null)
9+
public function getAllData(?string $table=null)
810
{
911
if (!isset($table)) {
1012
echo "Please provide your Supabase table name.";
@@ -16,7 +18,7 @@ public function getAllData($table=null)
1618
}
1719
}
1820

19-
public function getSingleData($table=null, $query=[])
21+
public function getSingleData(?string $table=null, array $query=[])
2022
{
2123
if (!isset($table)) {
2224
echo "Please provide your Supabase table name.";
@@ -30,7 +32,7 @@ public function getSingleData($table=null, $query=[])
3032
}
3133
}
3234

33-
public function postData($table=null, $query=[], $on_conflict=null)
35+
public function postData(?string $table=null, array $query=[], ?string $on_conflict=null)
3436
{
3537
if (!isset($table)) {
3638
echo "Please provide your Supabase table name.";
@@ -49,7 +51,7 @@ public function postData($table=null, $query=[], $on_conflict=null)
4951
}
5052
}
5153

52-
public function updateData($table=null, ?int $id=null, $query=[])
54+
public function updateData(?string $table=null, ?int $id=null, array $query=[])
5355
{
5456
if (!isset($table)) {
5557
echo "Please provide your Supabase table name.";
@@ -64,7 +66,7 @@ public function updateData($table=null, ?int $id=null, $query=[])
6466
}
6567
}
6668

67-
public function deleteData($table=null, ?int $id=null)
69+
public function deleteData(?string $table=null, ?int $id=null)
6870
{
6971
if (!isset($table)) {
7072
echo "Please provide your Supabase table name.";
@@ -77,23 +79,23 @@ public function deleteData($table=null, ?int $id=null)
7779
}
7880
}
7981

80-
public function pages($table=null)
82+
public function pages(?string $table=null)
8183
{
8284
$path = "$this->url/$table?select=*";
8385
$html = $this->grab($path, "GET");
8486
$data = json_decode($html, true);
8587
return $data;
8688
}
8789

88-
public function filter($table=null, ?int $range=null)
90+
public function filter(?string $table=null, ?int $range=null)
8991
{
9092
$path = "$this->url/$table?id=eq.$range&select=*";
9193
$html = $this->grab($path, "GET");
9294
$data = json_decode($html, true);
9395
return $data;
9496
}
9597

96-
public function matchs($table=null, $query=[])
98+
public function matchs(?string $table=null, array $query=[])
9799
{
98100
$path = "$this->url/$table";
99101
$html = $this->grab($path, "POST", json_encode($query));

src/Supabase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct(?string $url=null, ?string $apikey=null)
2121
}
2222
}
2323

24-
protected function grab($url, $method, $data=null)
24+
protected function grab(string $url, string $method, ?string $data=null)
2525
{
2626
$headers = array(
2727
"apikey: $this->apikey",

0 commit comments

Comments
 (0)