AnonymizableMock::getIdentifier()   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 0
1
<?php
2
/**
3
 * integer_net Magento Module
4
 *
5
 * @category   IntegerNet
6
 * @package    IntegerNet_Anonymizer
7
 * @copyright  Copyright (c) 2015 integer_net GmbH (http://www.integer-net.de/)
8
 * @author     Fabian Schmengler <[email protected]>
9
 */
10
11
namespace IntegerNet\Anonymizer\Mock;
12
13
14
use IntegerNet\Anonymizer\Implementor\AnonymizableEntity;
15
use IntegerNet\Anonymizer\AnonymizableValue;
16
17
/**
18
 * Dumb implementation of AnonymizableEntity that generates AnonymizableValue instances from test data
19
 *
20
 * @package IntegerNet\Anonymizer\Mock
21
 */
22
class AnonymizableMock implements AnonymizableEntity
23
{
24
    const __CLASS = __CLASS__;
25
26
    private $data = array();
27
    private $identifier = '';
28
    private $uniqueKey = null;
29
30
    /**
31
     * @param mixed[] $data data in the form [formatter => value], the first entry will be used as identifier
32
     * @param string|null $uniqueKey
33
     */
34
    function __construct($data = array(), $uniqueKey = 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...
35
    {
36
        $this->uniqueKey = $uniqueKey;
37
        $this->setRawData($data);
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    function getIdentifier()
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...
44
    {
45
        return $this->identifier;
46
    }
47
48
    /**
49
     * @return AnonymizableValue[]
50
     */
51
    function getValues()
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...
52
    {
53
        return $this->data;
54
    }
55
56
    /**
57
     * Sets raw data from database
58
     *
59
     * @param string[] $data
60
     * @return void
61
     */
62
    function setRawData($data)
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...
63
    {
64
        foreach ($data as $key => $value) {
65
            $this->data[] = new AnonymizableValue($key, $value, $this->uniqueKey === $key);
66
        }
67
        if (!empty($this->data)) {
68
            $this->identifier = reset($this->data)->getValue();
69
        }
70
    }
71
72
    /**
73
     * Update values in database
74
     *
75
     * @return mixed
76
     */
77
    function updateValues()
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...
78
    {
79
        // method stub. Should be mocked with PHPUnit to set expectations
80
    }
81
82
    /**
83
     * Reset to empty instance
84
     *
85
     * @return mixed
86
     */
87
    function clearInstance()
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...
88
    {
89
        $this->data = array();
90
        $this->identifier = '';
91
    }
92
93
    /**
94
     * Returns name of entity as translatable string
95
     *
96
     * @return string
97
     */
98
    function getEntityName()
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...
99
    {
100
        return 'Mock';
101
    }
102
103
}
104