Closed ghost closed 8 years ago
That's because the Wubs\Trakt\Response\Handlers\DefaultResponseHandler
has the following handle method:
<?php
/**
* @param ResponseInterface $response
* @param ClientInterface|GuzzleHttp\ClientInterface $client
* @return Collection
* @internal param ClientInterface $client
*/
public function handle(ResponseInterface $response, \GuzzleHttp\ClientInterface $client)
{
$json = $this->getJson($response);
$json = $this->getJson($response);
return (is_array($json)) ? collect($json) : collect([$json]);
}
The DefaultResponseHandler
class should always return a collection in order to adhere to it's return type and prevent unwanted results. If you expect a collection in consuming code but get an object, your code will break. Allways returning a collection, even with one item, will ensure polymorphism, aka, it can be used anywhere and give the expected result.
This is a question.
Why summary function return a single element array and not an object ?
fyi Documentation