Skip to content

Commit 945137e

Browse files
authored
Merge pull request #30 from CristalTeam/hotfix/find_one_with_null_argument
Allow passing null to find method
2 parents 914335c + 378804f commit 945137e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Api.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Cristal\ApiWrapper;
44

55
use Cristal\ApiWrapper\Concerns\HasCache;
6+
use Cristal\ApiWrapper\Exceptions\ApiEntityNotFoundException;
67
use Cristal\ApiWrapper\Transports\TransportInterface;
78

89
/**
@@ -55,7 +56,7 @@ public function __call($name, $arguments)
5556

5657
$endpoint = strtolower($matches[2]);
5758
if ('get' === $matches[1]) {
58-
if (!is_array($arguments[0] ?? [])) {
59+
if (array_key_exists(0, $arguments) && !is_array($arguments[0])) {
5960
return $this->findOne($endpoint, ...$arguments);
6061
}
6162

@@ -98,6 +99,12 @@ protected function findAll(string $endpoint, array $filters = []): array
9899
*/
99100
protected function findOne(string $endpoint, $id, array $filters = [])
100101
{
102+
// Makes no sense to proceed API call if we passed null id.
103+
// It would mean that we would like to do a findAll call instead and it could cause side effects.
104+
if ($id === null) {
105+
throw new ApiEntityNotFoundException([]);
106+
}
107+
101108
$uri = '/'.$endpoint.'/'.$id;
102109
$key = $uri.'?'.http_build_query($filters);
103110
if ($this->hasCache($key)) {

0 commit comments

Comments
 (0)