Completed
Push — master ( 86437d...3559e6 )
by diego
08:58
created

HashPassword::enable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.037

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 3
cp 0.6667
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1.037
1
<?php
2
3
declare(strict_types=1);
4
namespace HDNET\Importr\Feature;
5
6
use HDNET\Importr\Processor\Target;
7
use HDNET\Importr\Service\PasswordHashService;
8
9
/**
10
 * Class HashPassword.
11
 */
12
class HashPassword
13
{
14
    /**
15
     * @var PasswordHashService
16
     */
17
    protected $hashService;
18
19
    /**
20
     * RenameFile constructor.
21
     *
22
     * @param PasswordHashService $hashService
23
     */
24 1
    public function __construct(PasswordHashService $hashService)
25
    {
26 1
        $this->hashService = $hashService;
27 1
    }
28
29 1
    public static function enable()
30
    {
31 1
        FeatureRegistry::enable('preProcess', Target::class);
32
    }
33
34
    /**
35
     * @param array $configuration
36
     * @param array $entry
37
     *
38
     * @return array
39
     */
40
    public function execute(array $configuration, array $entry)
41
    {
42
        if (isset($configuration['filter']['password']) && \in_array($configuration['filter']['password'], $configuration['mapping'])) {
43
            $field = \array_search($configuration['filter']['password'], $configuration['mapping']);
44
            $entry[$field] = $this->hashService->hash($entry[$field]);
45
        }
46
47
        return [$configuration, $entry];
48
    }
49
}
50