Passed
Pull Request — master (#101)
by Łukasz
03:05
created

SendActivationMailListener::getSubscribedEvents()   A

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
nc 1
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 0
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
namespace FSi\Bundle\AdminSecurityBundle\EventListener;
11
12
use FSi\Bundle\AdminSecurityBundle\Event\AdminSecurityEvents;
13
use FSi\Bundle\AdminSecurityBundle\Event\UserEvent;
14
use FSi\Bundle\AdminSecurityBundle\Mailer\MailerInterface;
15
use FSi\Bundle\AdminSecurityBundle\Security\Token\TokenFactoryInterface;
16
use FSi\Bundle\AdminSecurityBundle\Security\User\ActivableInterface;
17
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
18
19
class SendActivationMailListener implements EventSubscriberInterface
20
{
21
    /**
22
     * @var MailerInterface
23
     */
24
    private $mailer;
25
26
    /**
27
     * @var TokenFactoryInterface
28
     */
29
    private $tokenFactory;
30
31
    function __construct(MailerInterface $mailer, TokenFactoryInterface $tokenFactory)
32
    {
33
        $this->mailer = $mailer;
34
        $this->tokenFactory = $tokenFactory;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public static function getSubscribedEvents()
41
    {
42
        return [
43
            AdminSecurityEvents::USER_CREATED => 'onUserCreated'
44
        ];
45
    }
46
47
    /**
48
     * @param UserEvent $event
49
     */
50
    public function onUserCreated(UserEvent $event)
51
    {
52
        $user = $event->getUser();
53
54
        if (($user instanceof ActivableInterface) && !$user->isEnabled()) {
55
            $user->setActivationToken($this->tokenFactory->createToken());
56
            $this->mailer->send($event->getUser());
0 ignored issues
show
Bug introduced by
$event->getUser() of type Symfony\Component\Securi...r\AdvancedUserInterface is incompatible with the type FSi\Bundle\AdminSecurity...iler\EmailableInterface expected by parameter $to of FSi\Bundle\AdminSecurity...MailerInterface::send(). ( Ignorable by Annotation )

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

56
            $this->mailer->send(/** @scrutinizer ignore-type */ $event->getUser());
Loading history...
57
        }
58
    }
59
}
60