Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notice: Trying to get property 'earned' of non-object in #93

Open
Argosth opened this issue May 22, 2019 · 20 comments
Open

Notice: Trying to get property 'earned' of non-object in #93

Argosth opened this issue May 22, 2019 · 20 comments

Comments

@Argosth
Copy link

Argosth commented May 22, 2019

Hi, good morning, I found this problem when I use the API.

I got the token I can consult almost all the information, when I put the next code:

$games = $client->user('Argosth')->games();

I got this result:

Resident Evil 7: Biohazard has 38 trophies Notice: Undefined property: stdClass::$comparedUser in C:\xampp\htdocs\Argosth\vendor\tustin\psn-php\src\Api\Trophy.php on line 101

Notice: Trying to get property 'earned' of non-object in C:\xampp\htdocs\Argosth\vendor\tustin\psn-php\src\Api\Trophy.php on line 101

Fatal error: Uncaught TypeError: Return value of PlayStation\Api\Trophy::earned() must be of the type bool, null returned in C:\xampp\htdocs\Argosth\vendor\tustin\psn-php\src\Api\Trophy.php:102 Stack trace: #0 C:\xampp\htdocs\Argosth\admin\psn.php(160): PlayStation\Api\Trophy->earned() #1 {main} thrown in C:\xampp\htdocs\Argosth\vendor\tustin\psn-php\src\Api\Trophy.php on line 102

Now, when I use the Tustin Account:

$games = $client->user('tustin25')->games();

I get more results:

Call of Duty®: Black Ops 4 has 53 trophies [bronze] My Home is the Arena - In IX, survive to Round 20 without opening a gate (earn rate - 1.20%) [silver] Venerated Warrior - In IX, defeat the most venerated opponent (earn rate - 1.20%) [bronze] Skilled Adversary - In IX have a Challenge banner with all 9 medallions (earn rate - 2.30%) [bronze] The Slaughterhouse - In IX, dismember 13 limbs in a single game while in The Pit (earn rate - 12.30%) [bronze] Gong like the Wind - In IX, defeat all 8 challengers summoned by a gong within 5 minutes (earn rat

But in the final result, there is the next error:

Notice: Undefined property: stdClass::$comparedUser in C:\xampp\htdocs\Argosth\vendor\tustin\psn-php\src\Api\Trophy.php on line 101

Notice: Trying to get property 'earned' of non-object in C:\xampp\htdocs\Argosth\vendor\tustin\psn-php\src\Api\Trophy.php on line 101

Fatal error: Uncaught TypeError: Return value of PlayStation\Api\Trophy::earned() must be of the type bool, null returned in C:\xampp\htdocs\Argosth\vendor\tustin\psn-php\src\Api\Trophy.php:102 Stack trace: #0 C:\xampp\htdocs\Argosth\admin\psn.php(160): PlayStation\Api\Trophy->earned() #1 {main} thrown in C:\xampp\htdocs\Argosth\vendor\tustin\psn-php\src\Api\Trophy.php on line 102

So, I don't know why some users have more results and other less, but the same error at the end.

I hope you can help me, thank you and have a nice day.

@mrcrazylee
Copy link
Contributor

I think I ran into the same issue as well. I will try to investigate in the coming days/weekend as well. I'll share what I've found when I have something to share. Maybe a bit off topic, as this repo is a php wrapper for the sony playstation api, can I read that API somewhere? Probably you need to have a dev account or something. It would make debugging a bit easier, as it gets easier to check the typing of this wrapper against the API documentation. I could not find the documentation anywhere myself.

@jbdabes
Copy link
Collaborator

jbdabes commented May 23, 2019

I think I ran into the same issue as well. I will try to investigate in the coming days/weekend as well. I'll share what I've found when I have something to share. Maybe a bit off topic, as this repo is a php wrapper for the sony playstation api, can I read that API somewhere? Probably you need to have a dev account or something. It would make debugging a bit easier, as it gets easier to check the typing of this wrapper against the API documentation. I could not find the documentation anywhere myself.

Unfortunately there is (currently) no public API. This library uses the "private" API that Sony has in place for its own apps and such, and therefore there is no documentation.

@mrcrazylee
Copy link
Contributor

@jbdabes Thanks for the reply. Will do it the old fashioned way then :).

@Argosth
Copy link
Author

Argosth commented May 23, 2019

My question is, why is the comparedUser property giving errors?

I also realise that using other options, I get 36 results, so I think that's the maximum amount of the array we can get.

I hope you masters can find a solution. Thank you.

@jbdabes
Copy link
Collaborator

jbdabes commented May 24, 2019

Hi, good morning, I found this problem when I use the API.

I got the token I can consult almost all the information, when I put the next code:

$games = $client->user('Argosth')->games();

I got this result:

Resident Evil 7: Biohazard has 38 trophies Notice: Undefined property: stdClass::$comparedUser in C:\xampp\htdocs\Argosth\vendor\tustin\psn-php\src\Api\Trophy.php on line 101

Notice: Trying to get property 'earned' of non-object in C:\xampp\htdocs\Argosth\vendor\tustin\psn-php\src\Api\Trophy.php on line 101

Fatal error: Uncaught TypeError: Return value of PlayStation\Api\Trophy::earned() must be of the type bool, null returned in C:\xampp\htdocs\Argosth\vendor\tustin\psn-php\src\Api\Trophy.php:102 Stack trace: #0 C:\xampp\htdocs\Argosth\admin\psn.php(160): PlayStation\Api\Trophy->earned() #1 {main} thrown in C:\xampp\htdocs\Argosth\vendor\tustin\psn-php\src\Api\Trophy.php on line 102

Now, when I use the Tustin Account:

$games = $client->user('tustin25')->games();

I get more results:

Call of Duty®: Black Ops 4 has 53 trophies [bronze] My Home is the Arena - In IX, survive to Round 20 without opening a gate (earn rate - 1.20%) [silver] Venerated Warrior - In IX, defeat the most venerated opponent (earn rate - 1.20%) [bronze] Skilled Adversary - In IX have a Challenge banner with all 9 medallions (earn rate - 2.30%) [bronze] The Slaughterhouse - In IX, dismember 13 limbs in a single game while in The Pit (earn rate - 12.30%) [bronze] Gong like the Wind - In IX, defeat all 8 challengers summoned by a gong within 5 minutes (earn rat

But in the final result, there is the next error:

Notice: Undefined property: stdClass::$comparedUser in C:\xampp\htdocs\Argosth\vendor\tustin\psn-php\src\Api\Trophy.php on line 101

Notice: Trying to get property 'earned' of non-object in C:\xampp\htdocs\Argosth\vendor\tustin\psn-php\src\Api\Trophy.php on line 101

Fatal error: Uncaught TypeError: Return value of PlayStation\Api\Trophy::earned() must be of the type bool, null returned in C:\xampp\htdocs\Argosth\vendor\tustin\psn-php\src\Api\Trophy.php:102 Stack trace: #0 C:\xampp\htdocs\Argosth\admin\psn.php(160): PlayStation\Api\Trophy->earned() #1 {main} thrown in C:\xampp\htdocs\Argosth\vendor\tustin\psn-php\src\Api\Trophy.php on line 102

So, I don't know why some users have more results and other less, but the same error at the end.

I hope you can help me, thank you and have a nice day.

Can you share your code with me so I can test this for myself? Using the code you provided works fine on my dev environment (PHP 7.3).

jbdabes added a commit that referenced this issue May 24, 2019
@jbdabes
Copy link
Collaborator

jbdabes commented May 24, 2019

Alright, so with some digging I've discovered this is limited to specific games (in the given example, it's The Evil Within 2). I'm not sure why but it doesn't seem to return the comparing user. I've added a temp fix which for now will return false for any games that does not pass this data back and have notified Tustin about looking into this specific issue a little deeper.

@Argosth
Copy link
Author

Argosth commented May 24, 2019 via email

@jbdabes
Copy link
Collaborator

jbdabes commented May 24, 2019

That was so weird too, the thing is, I have played The Evil With In 2, but I don't have the game or trophies loaded to psn, I have the Evil Within the first delivered complete 100%. How can I apply the fix JB? Thank you.

Best way right now would be to update your composer.json file to install tustin/psn-php pulling from dev-master:

"require": {
    "tustin/psn-php": "dev-master"
},

Then just composer update.

I'll tag a new release once we've gotten a few other things fixed - when this is done I'd recommend using ^2.1 instead of dev-master.

You may need to run composer clearcache before it finds the latest commit.

@Argosth
Copy link
Author

Argosth commented May 24, 2019

Hi again, I've been doing some test to see which functions are not working properly, and at this moment, this is my experience:

game.php errors:
- Platinum earned() return nothing and stops the api.
- User(): same problem.

trophyGroup errors:
- Progress(): Fatal error: Uncaught TypeError: Return value of PlayStation\Api\TrophyGroup::progress() must be of the type int, null returned.
- lastEarnedDate(): Similar error that above.
- lastUpdateDate(): Similar, problemas with compare() funciton.

Different Results dependind of the user:
- Every user has a different results, for example, in my case, using "Argosth I get 15 of 30 games and no my trophies.
- When I use the "tustin25" account, I get more results with trophies.
- When the nickname of a friend "CRsiete" I get even 60 games a more trophies than me or tustin25.

I don't really understand why some users retrieve more results than others.

Thank you and have a nice day.

@mrcrazylee
Copy link
Contributor

mrcrazylee commented May 24, 2019

@Argosth I've bumped into these errors as well. Currently working on a PR to change the game class a bit. I hope to have a pull request by tomorrow.

In my PR i'll be solely focussing on the errors you describe in game.php. I'll pull some methods apart as in some cases they do multiple things. Getting a boolean as result in one scenario and an object in another scenario can be a bit unpredictable.

@Tustin
Copy link
Owner

Tustin commented May 24, 2019

@mrcrazylee Appreciate it. I've been trying to get back to working on this library and realized I did some pretty dumb things when I rewrote this lol. I was trying to keep it as simple as possible by having some methods do multiple things which isn't really a good idea.

As for this problem, if that PR doesn't solve it I can take a look at this. I don't remember ever encountering a problem like this so it could be something new that Sony did in the API that I haven't accounted for yet.

@mrcrazylee
Copy link
Contributor

mrcrazylee commented May 24, 2019

Sure thing. First things first, I love that you have taken the time to setup this library! And I am by no means a pro at this, I am just trying to contribute where I can. As I am just a frontender by nature, please also look at my PR's with a sceptical eye. Believe you me, a couple of years ago I would probably have done the same. Again credits for putting your time and effort into this.

I can definitely see Sony changing its API. As you mentioned before, it is a private API. I think I have the bugs in the game.php file covered. Just need to do some additional testing to see how it is implemented in the other files of this library. Locally I think I've got it working, but I just want to be sure :)

@jbdabes
Copy link
Collaborator

jbdabes commented May 24, 2019

When @Tustin finishes up writing tests it should make spotting issues like this a lot easier!

@mrcrazylee
Copy link
Contributor

mrcrazylee commented May 26, 2019

@Argosth The problems you encounter in Game.php should be solved with this PR: #94

@Argosth
Copy link
Author

Argosth commented May 27, 2019

@mrcrazylee Thank you very much, I've applied the modifications, it seems that now there are less errors.

I still have the problem of only 15 games in total, and "The Evil Within 2" a game that I don't have but maybe is a problem of my profile perhaps.

Other errors I found are located in Trophy.php and TrophyGroup.php, related with the function lastEarnedDate() and earnedDate() for example:

Notice: Undefined property: stdClass::$comparedUser in C:\xampp\htdocs\Argosth\vendor\tustin\psn-php\src\Api\TrophyGroup.php on line 92

Notice: Trying to get property 'lastUpdateDate' of non-object in C:\xampp\htdocs\Argosth\vendor\tustin\psn-php\src\Api\TrophyGroup.php on line 92

Thank you very much for your effort and have a nice day.

@Argosth
Copy link
Author

Argosth commented May 30, 2019

Good morning, I want to say that I'm willing to help in this protect, but the thing is, I'm not a PHP expert, but I want to help, is there a way in what I can be useful?

Thank you.

@FleyX
Copy link
Contributor

FleyX commented Aug 16, 2019

I had submitted a pr to solve it.

@Ragowit
Copy link
Collaborator

Ragowit commented Sep 17, 2019

Getting this error as well. Does the upcoming 2.2 or the PR solve the problem? And if so, when will it become available?

@Krisseck
Copy link
Contributor

I don't know much about this library or PSN, but I got it working with this fix:

in src/Api/Trophy.php, there is function like this:

public function earned() : bool
    {
        return $this->comparing() ?
        $this->trophy->comparedUser->earned :
        $this->trophy->fromUser->earned;
    }

I replaced it with this function:

public function earned() : bool
    {
        if($this->comparing()) {
            if(isset($this->trophy->comparedUser)) {
                return $this->trophy->comparedUser->earned;
            }
        }

        return isset($this->trophy->fromUser) ? $this->trophy->fromUser->earned : false;
    }

So better checking if comparedUser is set or not

@Ragowit
Copy link
Collaborator

Ragowit commented Dec 12, 2019

This was solved with 6a608a3, correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants