Passed
Push — master ( 1fd71c...811f65 )
by Nicolas
03:35
created

UserProcessor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\DataFixtures\Processor;
4
5
use App\Entity\User;
6
use Fidry\AliceDataFixtures\ProcessorInterface;
7
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
8
9
/**
10
 * UserPasswordProcessor.
11
 */
12
final class UserProcessor implements ProcessorInterface
13
{
14
    /**
15
     * @var UserPasswordEncoderInterface
16
     */
17
    private $encoder;
18
19
    /**
20
     * @param UserPasswordEncoderInterface $encoder
21
     */
22
    public function __construct(UserPasswordEncoderInterface $encoder)
23
    {
24
        $this->encoder = $encoder;
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function preProcess(string $fixtureId, $object): void
31
    {
32
        /** @var User $object * */
33
        if (false === $object instanceof User) {
34
            return;
35
        }
36
37
        $object->setPassword($this->encoder->encodePassword($object, $object->getPassword()));
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function postProcess(string $fixtureId, $object): void
44
    {
45
        // nothing to do
46
    }
47
}
48