UserProcessor::__construct()   A
last analyzed

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 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace App\DataFixtures\Processor;
4
5
use App\Document\User;
6
use Fidry\AliceDataFixtures\ProcessorInterface;
7
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
8
9
class UserProcessor implements ProcessorInterface
10
{
11
    protected $encoder;
12
13
    public function __construct(UserPasswordEncoderInterface $encoder)
14
    {
15
        $this->encoder = $encoder;
16
    }
17
18
    public function preProcess(string $id, $object): void
19
    {
20
        if (!$object instanceof User) {
21
            return;
22
        }
23
24
        if ($object->getPlainPassword()) {
25
            $password = $this->encoder->encodePassword($object, $object->getPlainPassword());
26
            $object->setPassword($password);
27
        }
28
    }
29
30
    public function postProcess(string $id, $object): void
31
    {
32
    }
33
}
34