Completed
Push — development ( bff125...0f5c1f )
by Fabian
07:22
created

AnonymizableMock::updateValues()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 1
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
     * @var bool
31
     */
32
    private $isAnonymizable;
33
34
    /**
35
     * @param mixed[] $data data in the form [formatter => value], the first entry will be used as identifier
36
     * @param string|null $uniqueKey
37
     */
38
    function __construct($data = array(), $uniqueKey = null, $isAnonymizable = true)
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...
39
    {
40
        $this->uniqueKey = $uniqueKey;
41
        $this->setRawData($data);
42
        $this->isAnonymizable = $isAnonymizable;
43
    }
44
45
    function isAnonymizable()
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...
46
    {
47
        return $this->isAnonymizable;
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    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...
54
    {
55
        return $this->identifier;
56
    }
57
58
    /**
59
     * @return AnonymizableValue[]
60
     */
61
    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...
62
    {
63
        return $this->data;
64
    }
65
66
    /**
67
     * Sets raw data from database
68
     *
69
     * @param string[] $data
70
     * @return void
71
     */
72
    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...
73
    {
74
        foreach ($data as $key => $value) {
75
            $this->data[] = new AnonymizableValue($key, $value, $this->uniqueKey === $key);
76
        }
77
        if (!empty($this->data)) {
78
            $this->identifier = reset($this->data)->getValue();
79
        }
80
    }
81
82
    /**
83
     * Update values in database
84
     *
85
     * @return mixed
86
     */
87
    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...
88
    {
89
        // method stub. Should be mocked with PHPUnit to set expectations
90
    }
91
92
    /**
93
     * Reset to empty instance
94
     *
95
     * @return mixed
96
     */
97
    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...
98
    {
99
        $this->data = array();
100
        $this->identifier = '';
101
    }
102
103
    /**
104
     * Returns name of entity as translatable string
105
     *
106
     * @return string
107
     */
108
    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...
109
    {
110
        return 'Mock';
111
    }
112
113
}
114