Tustin / psn-php

A PHP wrapper for the PSN API
https://tustin.dev/psn-php/
MIT License
354 stars 73 forks source link

Concept null data when fetched through gameList fix #207

Closed gabetavares closed 2 years ago

gabetavares commented 2 years ago

Problem

When fetching Concepts through gameList some apps have the concept id but has no other information to be plucked, this often occur when fetching non-game apps, like HBO, Spotify, Netflix...

At JsonStream.php:39, Tustin\Haste\Http\JsonStream->jsonSerialize() you can catch an error on store front with message Store Front: There is no required storefront for this concept. and error code 3162368 maybe it could be useful implement an Exception to handle some errors.

The concept is:

"concept": {
    "id": 221898,
    "name": "HBO Max",
    "country": "US",
    "language": "en"
  }
  ...
}

Stack trace

I traced the problem until the jsonSerialize() where the conceptRetrieve is null, this value returned to Concept will throw the error since it's expecting a string.

JsonStream.php:39, Tustin\Haste\Http\JsonStream->jsonSerialize()
HttpClient.php:37, Tustin\Haste\Http\HttpClient->get()
Api.php:48, Tustin\PlayStation\Api->graphql()
Concept.php:50, Tustin\PlayStation\Model\Store\Concept->fetch()
Model.php:42, Tustin\PlayStation\Model->performFetch()
Model.php:69, Tustin\PlayStation\Model->pluck()
Concept.php:43, Tustin\PlayStation\Model\Store\Concept->publisher()
{
    "conceptRetrieve": null
}

Solution

My solution was, instead of modify the pluck() create another function on model to handle the null values and always return a string to avoid side effects on other classes.

Also I created the unit test for the Concept null values.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.