Anonymizer::_getFieldIdentifier()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
nc 1
nop 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: fs
5
 * Date: 16.03.2015
6
 * Time: 18:31
7
 */
8
9
namespace IntegerNet\Anonymizer;
10
11
12
use IntegerNet\Anonymizer\Implementor\AnonymizableEntity;
13
14
class Anonymizer
15
{
16
    const __CLASS = __CLASS__;
17
    /**
18
     * @var Provider
19
     */
20
    private $provider;
21
22
    /**
23
     * @param Provider $provider
24
     * @param string $locale
25
     */
26
    function __construct(Provider $provider = null, $locale = null)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
27
    {
28
        if ($provider === null) {
29
            $provider = new Provider();
30
        }
31
        $this->provider = $provider;
32
        $this->provider->initialize($locale);
33
    }
34
35
    /**
36
     * @param AnonymizableEntity[] $inputData
37
     */
38
    public function anonymize(array $inputData)
39
    {
40
        foreach ($inputData as $entity) {
41
            foreach ($entity->getValues() as $value) {
42
                $value->setValue($this->provider->getFakerData(
43
                    $value->getFakerFormatter(), $this->_getFieldIdentifier($entity, $value), $value->isUnique()));
44
            }
45
        }
46
    }
47
48
    /**
49
     * Returns identifier for a field, based on entity and current value. This is used to map real data to fake
50
     * data in the same way for each unique entity identifier (i.e. customer id)
51
     *
52
     * @param AnonymizableEntity $entity
53
     * @param AnonymizableValue $value
54
     * @return string
55
     */
56
    private function _getFieldIdentifier(AnonymizableEntity $entity, AnonymizableValue $value)
57
    {
58
        return sprintf('%s|%s', $entity->getIdentifier(), join('', (array)$value->getValue()));
59
    }
60
61
    public function resetUniqueGenerator()
62
    {
63
        $this->provider->resetUniqueGenerator();
64
    }
65
}