Completed
Push — master ( 1de9b7...830752 )
by Kristof
38:46 queued 24:09
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
    /** @var EntityManager */
10
    private $em;
11
12
    /** @var string */
13
    private $userClass;
14
15
    /**
16
     * OAuthUserCreator constructor.
17
     *
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
     * {@inheritdoc}
29
     */
30
    public function findUserByGoogleSignInData($email, $googleId)
31
    {
32
        //Check if already logged in before via Google auth
33
        $user = $this->em->getRepository($this->userClass)
34
            ->findOneBy(array('googleId' => $googleId));
35
36
        if (!$user instanceof $this->userClass) {
37
            //Check if Email was already present in database but not logged in via Google auth
38
            $user = $this->em->getRepository($this->userClass)
39
                ->findOneBy(array('email' => $email));
40
41
            if (!$user instanceof $this->userClass) {
42
                //Last chance try looking for email address in username field
43
                $user = $this->em->getRepository($this->userClass)
44
                    ->findOneBy(array('username' => $email));
45
            }
46
        }
47
48
        return $user;
49
    }
50
}
51