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

UserProcessor::preProcess()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 8
ccs 0
cts 4
cp 0
crap 6
rs 9.4285
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