manuakasam/SamUser

SamUser\Entity\User's setters don't return $this

silenzium opened this issue · 3 comments

I'm new to ZF2 and Doctrine but I have a Problem with scnSocialAuth, using the SamUser User Entity. When logging in via i.e. facebook I get the following error:

Call to a member function setDisplayName() on a non-object in /.../vendor/socalnick/scn-social-auth/src/ScnSocialAuth/Authentication/Adapter/HybridAuth.php on line 343

The setters are chained so the second set throws the error:

$localUser->setEmail($userProfile->emailVerified)
->setDisplayName($userProfile->displayName)
->setPassword(__FUNCTION__);

For now I created and use my own UserEntity that extends yours to prevent composer updates to override the changes.

The root for this problem is actually ZfcUser itself. The UserInterface only defines the getter-functions. Therefore all modules working with ZfcUser can ONLY be sure that getter functions do exist. Setter-functions aren't even defined by the UserInterface itself.

Furthermore relying on Setter functions to be chainable is not that great of a thing to do, ESPECIALLY, if there's no Interface defining it.

As long as you're OK with your solution that'd be fine. I have no problem adding this though, so hopefully I'll get around to do this soon (it's really just a 2 minute work) :P

Thanks Sam, I went fine with my solution in that particular project but your points makes total sense to me. Didn't know much about Interfaces before but also with the help of the article by Ocramius I really understand now (thanks for that Ocramius, the author of scnSocialAuth should read it too..).
I won't use a fluent interface design for my entities from now on.

Thanks again for the lesson ;)

and sorry for the very late response btw..