PasswordUpdaterListener::customerUpdateEvent()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
nc 3
cc 3
nop 1
1
<?php
2
3
/*
4
 * This file is part of AppName.
5
 *
6
 * (c) Monofony
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
namespace App\EventListener;
13
14
use App\Entity\Customer\CustomerInterface;
15
use Sylius\Bundle\UserBundle\EventListener\PasswordUpdaterListener as BasePasswordUpdaterListener;
16
use Sylius\Component\Resource\Exception\UnexpectedTypeException;
17
use Symfony\Component\EventDispatcher\GenericEvent;
18
19
final class PasswordUpdaterListener extends BasePasswordUpdaterListener
20
{
21
    /**
22
     * @param GenericEvent $event
23
     */
24
    public function customerUpdateEvent(GenericEvent $event): void
25
    {
26
        $customer = $event->getSubject();
27
28
        if (!$customer instanceof CustomerInterface) {
29
            throw new UnexpectedTypeException(
30
                $customer,
31
                CustomerInterface::class
32
            );
33
        }
34
35
        if (null !== $user = $customer->getUser()) {
36
            $this->updatePassword($user);
37
        }
38
    }
39
}
40