Tustin / psn-php

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

Trophy::earned returns null #234

Closed Ragowit closed 1 year ago

Ragowit commented 1 year ago
[13-Dec-2022 20:02:06 UTC] PHP Fatal error:  Uncaught TypeError: Tustin\PlayStation\Model\Trophy\Trophy::earned(): Return value must be of type bool, null returned in /home/psn100/public_html/vendor/tustin/psn-php/src/Model/Trophy/Trophy.php:129

I know the profile is HETARE69 but don't have specific game or trophy yet.

Tustin commented 1 year ago

If you can find the trophy with that issue that would be great. I tried iterating through all the trophies that user has but there's way too many. It's possible that it might be some super old trophy list that is missing that value for some reason.

Ragowit commented 1 year ago

It can have been some hiccup when I updated... Looking through the code right now to see if I get the error again.

Ragowit commented 1 year ago

np_communication_id: NPWR33147_00 group_id: default order_id: 0 account_id: 441308995318026967 earned_date: 2022-12-13 15:55:24 progress: earned: [errors out]

Ragowit commented 1 year ago

I have an if-check for earned before that seems to work. It stops working if I call it a second time?

Tustin commented 1 year ago

Weird, this is the code I'm testing with, and it seems to be okay. I even tried calling earned twice with no issues.

foreach ($account->trophyTitles() as $title)
{
    if ($title->npCommunicationId() != 'NPWR33147_00')
    {
        continue;
    }

    $groups = $title->trophyGroups();

    foreach ($groups as $group)
    {
        foreach ($group->trophies() as $trophy)
        {
            if ($trophy->earned())
            {
                var_dump($trophy->earned());
            }
        }
    }

    die('hit it');
}
Ragowit commented 1 year ago

Well, I updated my code with $trophyEarned = $trophy->earned(); and then use the $trophyEarned instead. Seems to have solved my issue.

Dunno why.