SetEmailAsUsernameListener::getSubscribedEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
/**
4
 * (c) FSi sp. z o.o. <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace FSi\Bundle\AdminSecurityBundle\EventListener;
13
14
use FSi\Bundle\AdminSecurityBundle\Event\AdminSecurityEvents;
15
use FSi\Bundle\AdminSecurityBundle\Event\UserEvent;
16
use FSi\Bundle\AdminSecurityBundle\Security\User\UserInterface;
17
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
18
19
class SetEmailAsUsernameListener implements EventSubscriberInterface
20
{
21
    public static function getSubscribedEvents(): array
22
    {
23
        return [
24
            AdminSecurityEvents::USER_CREATED => 'setEmailAsUsername'
25
        ];
26
    }
27
28
    public function setEmailAsUsername(UserEvent $event): void
29
    {
30
        $user = $event->getUser();
31
        if (!$user instanceof UserInterface) {
32
            return;
33
        }
34
35
        $user->setUsername($user->getEmail());
0 ignored issues
show
Bug introduced by
It seems like $user->getEmail() can also be of type null; however, parameter $username of FSi\Bundle\AdminSecurity...nterface::setUsername() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
        $user->setUsername(/** @scrutinizer ignore-type */ $user->getEmail());
Loading history...
36
    }
37
}
38