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

UserProcessor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A preProcess() 0 8 2
A __construct() 0 3 1
A postProcess() 0 2 1
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