UserListener::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 2
b 0
f 1
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace PiedWeb\CMSBundle\EventListener;
4
5
use Doctrine\ORM\Event\PreUpdateEventArgs;
6
use PiedWeb\CMSBundle\Entity\UserInterface;
7
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
8
9
class UserListener
10
{
11
    protected $passwordEncoder;
12
13
    public function __construct(UserPasswordEncoderInterface $passwordEncoder)
14
    {
15
        $this->passwordEncoder = $passwordEncoder;
16
    }
17
18
    /**
19
     * Set Password on database update if PlainPassword is set.
20
     */
21
    public function preUpdate(UserInterface $user, PreUpdateEventArgs $event)
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed. ( Ignorable by Annotation )

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

21
    public function preUpdate(UserInterface $user, /** @scrutinizer ignore-unused */ PreUpdateEventArgs $event)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
22
    {
23
        if (\strlen($user->getPlainPassword()) > 0) {
24
            $user->setPassword($this->passwordEncoder->encodePassword($user, $user->getPlainPassword()));
25
            $user->eraseCredentials();
26
        }
27
    }
28
}
29