File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed
Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change 33namespace Cristal \ApiWrapper ;
44
55use Cristal \ApiWrapper \Concerns \HasCache ;
6+ use Cristal \ApiWrapper \Exceptions \ApiEntityNotFoundException ;
67use 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 )) {
You can’t perform that action at this time.
0 commit comments