UserManager::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 3
1
<?php
2
3
namespace Starkerxp\UserBundle\Manager;
4
5
use Doctrine\ORM\EntityManager;
6
use Starkerxp\StructureBundle\Entity\AbstractEntity;
7
use Starkerxp\StructureBundle\Manager\AbstractManager;
8
use Starkerxp\UserBundle\Entity\User;
9
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoder;
10
11
class UserManager extends AbstractManager
12
{
13
    /**
14
     * @var UserPasswordEncoder
15
     */
16
    private $serviceEncoder;
17
18
    public function __construct(EntityManager $entityManager, $entity, $serviceEncoder)
19
    {
20
        parent::__construct($entityManager, $entity);
21
        $this->serviceEncoder = $serviceEncoder;
22
    }
23
24
    public function getSupport(AbstractEntity $object)
25
    {
26
        return $object instanceof User;
27
    }
28
29
    protected function preInsert(User $user)
30
    {
31
        if ($user->getPlainPassword()) {
32
            $this->modifierLeMotDePasse($user);
33
        }
34
    }
35
36
    private function modifierLeMotDePasse(User $user)
37
    {
38
        $motDePasse = $this->serviceEncoder->encodePassword($user, $user->getPlainPassword());
39
        $user->setPassword($motDePasse);
40
    }
41
42
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
43