13
13
*/
14
14
class EntityDataObject
15
15
{
16
+ const NO_UNIQUE_PROCESS = 0 ;
17
+ const SUITE_UNIQUE_VALUE = 1 ;
18
+ const CEST_UNIQUE_VALUE = 2 ;
19
+ const SUITE_UNIQUE_NOTATION = 3 ;
20
+ const CEST_UNIQUE_NOTATION = 4 ;
21
+ const SUITE_UNIQUE_FUNCTION = 'msqs ' ;
22
+ const CEST_UNIQUE_FUNCTION = 'msq ' ;
23
+
16
24
/**
17
25
* Name of the entity
18
26
*
@@ -30,52 +38,45 @@ class EntityDataObject
30
38
/**
31
39
* An array of required entity name to corresponding type
32
40
*
33
- * @var array
41
+ * @var string[]
34
42
*/
35
43
private $ linkedEntities = [];
36
44
37
45
/**
38
46
* An array of variable mappings for static data
39
47
*
40
- * @var array
48
+ * @var string[]
41
49
*/
42
50
private $ vars ;
43
51
44
52
/**
45
53
* An array of Data Name to Data Value
46
54
*
47
- * @var array
55
+ * @var string[]
48
56
*/
49
57
private $ data = [];
50
58
51
- const NO_UNIQUE_PROCESS = 0 ;
52
- const SUITE_UNIQUE_VALUE = 1 ;
53
- const CEST_UNIQUE_VALUE = 2 ;
54
- const SUITE_UNIQUE_NOTATION = 3 ;
55
- const CEST_UNIQUE_NOTATION = 4 ;
56
- const SUITE_UNIQUE_FUNCTION = 'msqs ' ;
57
- const CEST_UNIQUE_FUNCTION = 'msq ' ;
58
-
59
59
/**
60
60
* Array of data name and its uniqueness attribute value.
61
61
*
62
- * @var array
62
+ * @var string[]
63
63
*/
64
64
private $ uniquenessData = [];
65
65
66
66
/**
67
- * EntityDataObject constructor.
68
- * @param string $entityName
69
- * @param string $entityType
70
- * @param array $data
71
- * @param array $linkedEntities
72
- * @param array $uniquenessData
73
- * @param array $vars
67
+ * Constructor
68
+ *
69
+ * @param string $name
70
+ * @param string $type
71
+ * @param string[] $data
72
+ * @param string[] $linkedEntities
73
+ * @param string[] $uniquenessData
74
+ * @param string[] $vars
74
75
*/
75
- public function __construct ($ entityName , $ entityType , $ data , $ linkedEntities , $ uniquenessData , $ vars = [])
76
+ public function __construct ($ name , $ type , $ data , $ linkedEntities , $ uniquenessData , $ vars = [])
76
77
{
77
- $ this ->name = $ entityName ;
78
- $ this ->type = $ entityType ;
78
+ $ this ->name = $ name ;
79
+ $ this ->type = $ type ;
79
80
$ this ->data = $ data ;
80
81
$ this ->linkedEntities = $ linkedEntities ;
81
82
if ($ uniquenessData ) {
@@ -86,17 +87,7 @@ public function __construct($entityName, $entityType, $data, $linkedEntities, $u
86
87
}
87
88
88
89
/**
89
- * Getter for linked entity names
90
- *
91
- * @return array
92
- */
93
- public function getLinkedEntities ()
94
- {
95
- return $ this ->linkedEntities ;
96
- }
97
-
98
- /**
99
- * Getter for entity name
90
+ * Get the name of this entity data object
100
91
*
101
92
* @return string
102
93
*/
@@ -106,7 +97,7 @@ public function getName()
106
97
}
107
98
108
99
/**
109
- * Getter for entity type
100
+ * Get the type of this entity data object
110
101
*
111
102
* @return string
112
103
*/
@@ -116,44 +107,37 @@ public function getType()
116
107
}
117
108
118
109
/**
119
- * Getter for Entity's data.
120
- * @return array
121
- */
122
- public function getData ()
123
- {
124
- return $ this ->data ;
125
- }
126
-
127
- /**
128
- * This function retrieves data from an entity defined in xml.
110
+ * Get a piece of data by name and the desired uniqueness format.
129
111
*
130
- * @param string $dataName
131
- * @param int $uniDataFormat
112
+ * @param string $name
113
+ * @param int $uniquenessFormat
132
114
* @return string|null
133
115
* @throws TestFrameworkException
134
116
*/
135
- public function getDataByName ($ dataName , $ uniDataFormat )
117
+ public function getDataByName ($ name , $ uniquenessFormat )
136
118
{
137
- if (!$ this ->isValidUniqueDataFormat ($ uniDataFormat )) {
119
+ if (!$ this ->isValidUniqueDataFormat ($ uniquenessFormat )) {
138
120
throw new TestFrameworkException (
139
- sprintf ('Invalid unique data format value: %s \n ' , $ uniDataFormat )
121
+ sprintf ('Invalid unique data format value: %s \n ' , $ uniquenessFormat )
140
122
);
141
123
}
142
124
143
- $ name = strtolower ($ dataName );
125
+ $ name_lower = strtolower ($ name );
144
126
145
- if ($ this ->data !== null && array_key_exists ($ name , $ this ->data )) {
146
- $ uniData = $ this ->getUniquenessDataByName ($ dataName );
147
- if (null === $ uniData || $ uniDataFormat == self ::NO_UNIQUE_PROCESS ) {
148
- return $ this ->data [$ name ];
127
+ if ($ this ->data !== null && array_key_exists ($ name_lower , $ this ->data )) {
128
+ $ uniquenessData = $ this ->getUniquenessDataByName ($ name_lower );
129
+ if (null === $ uniquenessData || $ uniquenessFormat == self ::NO_UNIQUE_PROCESS ) {
130
+ return $ this ->data [$ name_lower ];
149
131
}
150
- return $ this ->formatUniqueData ($ name , $ uniData , $ uniDataFormat );
132
+ return $ this ->formatUniqueData ($ name_lower , $ uniquenessData , $ uniquenessFormat );
151
133
}
134
+
152
135
return null ;
153
136
}
154
137
155
138
/**
156
139
* Formats and returns data based on given uniqueDataFormat and prefix/suffix.
140
+ *
157
141
* @param string $name
158
142
* @param string $uniqueData
159
143
* @param string $uniqueDataFormat
@@ -200,6 +184,7 @@ private function formatUniqueData($name, $uniqueData, $uniqueDataFormat)
200
184
201
185
/**
202
186
* Performs a check that the given uniqueness function exists, throws an exception if it doesn't.
187
+ *
203
188
* @param string $function
204
189
* @param string $uniqueDataFormat
205
190
* @return void
@@ -221,13 +206,13 @@ private function checkUniquenessFunctionExists($function, $uniqueDataFormat)
221
206
* Function which returns a reference to another entity (e.g. a var with entity="category" field="id" returns as
222
207
* category->id)
223
208
*
224
- * @param string $dataKey
209
+ * @param string $key
225
210
* @return string|null
226
211
*/
227
- public function getVarReference ($ dataKey )
212
+ public function getVarReference ($ key )
228
213
{
229
- if (array_key_exists ($ dataKey , $ this ->vars )) {
230
- return $ this ->vars [$ dataKey ];
214
+ if (array_key_exists ($ key , $ this ->vars )) {
215
+ return $ this ->vars [$ key ];
231
216
}
232
217
233
218
return null ;
@@ -237,15 +222,15 @@ public function getVarReference($dataKey)
237
222
* This function takes an array of entityTypes indexed by name and a string that represents the type of interest.
238
223
* The function returns an array of entityNames relevant to the specified type.
239
224
*
240
- * @param string $fieldType
225
+ * @param string $type
241
226
* @return array
242
227
*/
243
- public function getLinkedEntitiesOfType ($ fieldType )
228
+ public function getLinkedEntitiesOfType ($ type )
244
229
{
245
230
$ groupedArray = [];
246
231
247
232
foreach ($ this ->linkedEntities as $ entityName => $ entityType ) {
248
- if ($ entityType == $ fieldType ) {
233
+ if ($ entityType == $ type ) {
249
234
$ groupedArray [] = $ entityName ;
250
235
}
251
236
}
0 commit comments