Completed
Push — master ( 708acf...2df64c )
by Piotr
08:12 queued 10s
created

ResendActivationTokenBatchElement::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
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\Doctrine\Admin;
13
14
use FSi\Bundle\AdminBundle\Doctrine\Admin\BatchElement;
15
use FSi\Bundle\AdminSecurityBundle\Event\ActivationEvent;
16
use FSi\Bundle\AdminSecurityBundle\Event\AdminSecurityEvents;
17
use FSi\Bundle\AdminSecurityBundle\Security\User\ActivableInterface;
18
use RuntimeException;
19
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
20
21
final class ResendActivationTokenBatchElement extends BatchElement
22
{
23
    /**
24
     * @var string
25
     */
26
    private $userModel;
27
28
    /**
29
     * @var EventDispatcherInterface
30
     */
31
    private $eventDispatcher;
32
33
    public function __construct(EventDispatcherInterface $eventDispatcher, string $userModel, array $options)
34
    {
35
        parent::__construct($options);
36
37
        $this->userModel = $userModel;
38
        $this->eventDispatcher = $eventDispatcher;
39
    }
40
41
    public function getId(): string
42
    {
43
        return 'admin_security_reset_activation_token';
44
    }
45
46
    public function getClassName(): string
47
    {
48
        return $this->userModel;
49
    }
50
51
    /**
52
     * @param ActivableInterface $object
53
     */
54
    public function apply($object): void
55
    {
56
        if (false === $object instanceof ActivableInterface) {
57
            throw new RuntimeException(sprintf(
58
                'Expected an instance of "%s", got "%s" instead.',
59
                ActivableInterface::class,
60
                true === is_object($object) ? get_class($object) : gettype($object)
61
            ));
62
        }
63
64
        if (true === $object->isEnabled()) {
65
            return;
66
        }
67
68
        $this->eventDispatcher->dispatch(
69
            AdminSecurityEvents::RESEND_ACTIVATION_TOKEN,
0 ignored issues
show
Bug introduced by
FSi\Bundle\AdminSecurity...RESEND_ACTIVATION_TOKEN of type string is incompatible with the type object expected by parameter $event of Symfony\Contracts\EventD...erInterface::dispatch(). ( Ignorable by Annotation )

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

69
            /** @scrutinizer ignore-type */ AdminSecurityEvents::RESEND_ACTIVATION_TOKEN,
Loading history...
70
            new ActivationEvent($object)
0 ignored issues
show
Unused Code introduced by
The call to Symfony\Contracts\EventD...erInterface::dispatch() has too many arguments starting with new FSi\Bundle\AdminSecu...ctivationEvent($object). ( Ignorable by Annotation )

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

70
        $this->eventDispatcher->/** @scrutinizer ignore-call */ 
71
                                dispatch(

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
71
        );
72
    }
73
}
74