Passed
Push — v2 ( 9b853e...868892 )
by Daniel
04:58
created

UserChecker::checkPostAuth()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 2
ccs 0
cts 1
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Component Bundle Project
5
 *
6
 * (c) Daniel West <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Silverback\ApiComponentBundle\Security;
15
16
use Silverback\ApiComponentBundle\Entity\User\AbstractUser;
17
use Symfony\Component\Security\Core\Exception\DisabledException;
18
use Symfony\Component\Security\Core\User\UserCheckerInterface;
19
use Symfony\Component\Security\Core\User\UserInterface;
20
21
class UserChecker implements UserCheckerInterface
22
{
23
    private bool $denyUnverifiedLogin;
24
25
    public function __construct(bool $denyUnverifiedLogin)
26
    {
27
        $this->denyUnverifiedLogin = $denyUnverifiedLogin;
28
    }
29
30
    public function checkPreAuth(UserInterface $user): void
31
    {
32
        if (!$user instanceof AbstractUser) {
33
            return;
34
        }
35
36
        // user is deleted, show a generic Account Not Found message.
37
        if (!$user->isEnabled()) {
38
            throw new DisabledException('This user is currently disabled');
39
        }
40
41
        if ($this->denyUnverifiedLogin && !$user->isEmailAddressVerified()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $user->isEmailAddressVerified() of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
42
            throw new DisabledException('Please verify your email address before logging in. If you did not receive a confirmation email please try resetting your password using the forgot password feature.');
43
        }
44
    }
45
46
    public function checkPostAuth(UserInterface $user): void
47
    {
48
    }
49
}
50