Passed
Push — develop ( 49d2d6...5c0399 )
by Nicolas
03:53
created

UserProcessor::preProcess()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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