UserListener   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 6
dl 0
loc 17
rs 10
c 2
b 0
f 1
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A preUpdate() 0 5 2
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