Completed
Push — master ( 015490...3fff3d )
by diego
06:23 queued 04:33
created

HashPassword::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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
    public function __construct(PasswordHashService $hashService)
25
    {
26
        $this->hashService = $hashService;
27
    }
28
29
    public static function enable()
30
    {
31
        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