Completed
Push — master ( 91fdab...75a7b9 )
by
unknown
13:37
created

Helper/Security/OAuth/OAuthUserFinder.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\AdminBundle\Helper\Security\OAuth;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
7
class OAuthUserFinder implements OAuthUserFinderInterface
8
{
9
10
    /** @var EntityManager */
11
    private $em;
12
13
    /** @var string */
14
    private $userClass;
15
16
    /**
17
     * OAuthUserCreator constructor.
18
     * @param EntityManagerInterface $em
19
     * @param $userClass
20
     */
21
    public function __construct(EntityManagerInterface $em, $userClass)
22
    {
23
        $this->em = $em;
0 ignored issues
show
Documentation Bug introduced by
It seems like $em of type object<Doctrine\ORM\EntityManagerInterface> is incompatible with the declared type object<Kunstmaan\AdminBu...ty\OAuth\EntityManager> of property $em.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
24
        $this->userClass = $userClass;
25
    }
26
27
28
    /**
29
     * {@inheritDoc}
30
     */
31
    public function findUserByGoogleSignInData($email, $googleId)
32
    {
33
        //Check if already logged in before via Google auth
34
        $user = $this->em->getRepository($this->userClass)
35
            ->findOneBy(array('googleId' => $googleId));
36
37
        if (!$user instanceof $this->userClass) {
38
            //Check if Email was already present in database but not logged in via Google auth
39
            $user = $this->em->getRepository($this->userClass)
40
                ->findOneBy(array('email' => $email));
41
42
            if(!$user instanceof $this->userClass) {
43
                //Last chance try looking for email address in username field
44
                $user = $this->em->getRepository($this->userClass)
45
                    ->findOneBy(array('username' => $email));
46
            }
47
        }
48
49
        return $user;
50
    }
51
}
52