| Conditions | 1 |
| Paths | 1 |
| Total Lines | 22 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | public function amLoggedInAs($username) |
||
| 15 | { |
||
| 16 | $firewallContext = 'main'; |
||
| 17 | |||
| 18 | /** @var \AppBundle\Entity\Repository\UserRepository $userRepository */ |
||
| 19 | $userRepository = $this->getSymfonyModule()->grabService('app.entity.repository.user'); |
||
| 20 | |||
| 21 | /** @var \Symfony\Component\HttpFoundation\Session\Session $session */ |
||
| 22 | $session = $this->getSymfonyModule()->grabService('session'); |
||
| 23 | |||
| 24 | // Fetch user |
||
| 25 | $user = $userRepository->findOneBy(['login' => $username]); |
||
| 26 | |||
| 27 | // Create token and save to session and cookie |
||
| 28 | $token = new PostAuthenticationGuardToken($user, $firewallContext, $user->getRoles()); |
||
|
|
|||
| 29 | |||
| 30 | $session->set('_security_'.$firewallContext, serialize($token)); |
||
| 31 | $session->save(); |
||
| 32 | |||
| 33 | $cookieJar = $this->getSymfonyModule()->client->getCookieJar(); |
||
| 34 | $cookieJar->set(new Cookie($session->getName(), $session->getId())); |
||
| 35 | } |
||
| 36 | |||
| 49 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: