1 | <?php |
||
26 | abstract class AbstractAnonymizer |
||
27 | { |
||
28 | /** |
||
29 | * Constant to define the type of action for that table |
||
30 | */ |
||
31 | const TRUNCATE_TABLE = 1; |
||
32 | |||
33 | /** |
||
34 | * Constant to define the type of action for that table |
||
35 | */ |
||
36 | const UPDATE_TABLE = 2; |
||
37 | |||
38 | /** |
||
39 | * Contain the configuration object |
||
40 | * |
||
41 | * @var Reader |
||
42 | */ |
||
43 | protected $configuration; |
||
44 | |||
45 | /** |
||
46 | * Configuration of entities |
||
47 | * |
||
48 | * @var array |
||
49 | */ |
||
50 | protected $configEntites = []; |
||
51 | |||
52 | /** |
||
53 | * Process the entity according to the anonymizer type |
||
54 | * |
||
55 | * @param string $entity |
||
|
|||
56 | * @param callable|null $callback |
||
57 | * @param bool $pretend |
||
58 | * @param bool $returnResult |
||
59 | */ |
||
60 | abstract public function processEntity( |
||
66 | |||
67 | /** |
||
68 | * Set the configuration |
||
69 | * |
||
70 | * @param Reader $configuration |
||
71 | */ |
||
72 | 2 | public function setConfiguration(Reader $configuration) |
|
78 | |||
79 | /** |
||
80 | * Evaluate, from the configuration if I have to update or Truncate the table |
||
81 | * |
||
82 | * @param string $entity |
||
83 | * |
||
84 | * @return int |
||
85 | */ |
||
86 | 1 | public function whatToDoWithEntity(string $entity): int |
|
87 | { |
||
88 | 1 | $this->checkEntityIsInConfig($entity); |
|
89 | |||
90 | 1 | $entityConfig = $this->configEntites[$entity]; |
|
91 | |||
92 | 1 | $actions = 0; |
|
93 | 1 | if (array_key_exists('delete', $entityConfig) && $entityConfig['delete'] === true) { |
|
94 | $actions |= self::TRUNCATE_TABLE; |
||
95 | } |
||
96 | |||
97 | 1 | if (array_key_exists('cols', $entityConfig)) { |
|
98 | 1 | $actions |= self::UPDATE_TABLE; |
|
99 | } |
||
100 | |||
101 | 1 | return $actions; |
|
102 | } |
||
103 | |||
104 | /** |
||
105 | * Returns the 'delete_where' parameter for an entity in config (or empty) |
||
106 | * |
||
107 | * @param string $entity |
||
108 | * |
||
109 | * @return string |
||
110 | */ |
||
111 | public function getWhereConditionInConfig(string $entity): string |
||
112 | { |
||
113 | $this->checkEntityIsInConfig($entity); |
||
114 | |||
115 | if (!array_key_exists('delete_where', $this->configEntites[$entity])) { |
||
116 | return ''; |
||
117 | } |
||
118 | |||
119 | return $this->configEntites[$entity]['delete_where']; |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * Generate fake data for an entity and return it as an Array |
||
124 | * |
||
125 | * @param string $entity |
||
126 | * |
||
127 | * @return array |
||
128 | */ |
||
129 | 1 | public function generateFakeData(string $entity): array |
|
145 | |||
146 | /** |
||
147 | * Make sure that entity is defined in the configuration |
||
148 | * |
||
149 | * @param string $entity |
||
150 | * |
||
151 | * @throws NeuralizerConfigurationException |
||
152 | */ |
||
153 | 1 | private function checkEntityIsInConfig(string $entity) |
|
162 | } |
||
163 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.