Skip to content

Call to a member function getUser() on null if try to get trophies #266

@dark-cms

Description

@dark-cms

Version: 5.0.0.x-dev

I'm getting a bit desperate at the moment.

No matter what I try, I can't get my own trophies because the code exits at a certain point.

Breakdown of my Code:
I have completely reduced the code for the purpose of simplicity

 foreach ($this->me->trophyTitles() as $game) {
            if ($game->hasTrophies()) {
                foreach ($game->trophyGroups() as $trophyGroup) {
                    foreach ($trophyGroup->trophies() as $trophy) {

                    }
                }
            }

The Code throws an Exception:

Call to a member function getUser() on null

(https://github.com/Tustin/psn-php/blob/9a939e55b399d956319f8d4125f517ce4747da08/src/Iterator/TrophyGroupsIterator.php#L23C1-L29C15)

 if ($this->title instanceof UserTrophyTitle) {
            $results = $this->get(
                'trophy/v1/users/' . $this->title->getFactory()->getUser()->accountId() . '/npCommunicationIds/' . $this->title->npCommunicationId() . '/trophyGroups',
                [
                    'npServiceName' => $this->title->serviceName()
                ]
            );

When I test what $this->title->getFactory() returns, it is always null

Unfortunately, other issue entries have not helped me and the instructions are a bit old, so I hope someone can help me.
Basically, the endpoints fit to retrieve all my trophies (at least compared to another system)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions