1313 */
1414class EntityDataObject
1515{
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+
1624 /**
1725 * Name of the entity
1826 *
@@ -30,52 +38,45 @@ class EntityDataObject
3038 /**
3139 * An array of required entity name to corresponding type
3240 *
33- * @var array
41+ * @var string[]
3442 */
3543 private $ linkedEntities = [];
3644
3745 /**
3846 * An array of variable mappings for static data
3947 *
40- * @var array
48+ * @var string[]
4149 */
4250 private $ vars ;
4351
4452 /**
4553 * An array of Data Name to Data Value
4654 *
47- * @var array
55+ * @var string[]
4856 */
4957 private $ data = [];
5058
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-
5959 /**
6060 * Array of data name and its uniqueness attribute value.
6161 *
62- * @var array
62+ * @var string[]
6363 */
6464 private $ uniquenessData = [];
6565
6666 /**
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
7475 */
75- public function __construct ($ entityName , $ entityType , $ data , $ linkedEntities , $ uniquenessData , $ vars = [])
76+ public function __construct ($ name , $ type , $ data , $ linkedEntities , $ uniquenessData , $ vars = [])
7677 {
77- $ this ->name = $ entityName ;
78- $ this ->type = $ entityType ;
78+ $ this ->name = $ name ;
79+ $ this ->type = $ type ;
7980 $ this ->data = $ data ;
8081 $ this ->linkedEntities = $ linkedEntities ;
8182 if ($ uniquenessData ) {
@@ -86,17 +87,7 @@ public function __construct($entityName, $entityType, $data, $linkedEntities, $u
8687 }
8788
8889 /**
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
10091 *
10192 * @return string
10293 */
@@ -106,7 +97,7 @@ public function getName()
10697 }
10798
10899 /**
109- * Getter for entity type
100+ * Get the type of this entity data object
110101 *
111102 * @return string
112103 */
@@ -116,44 +107,37 @@ public function getType()
116107 }
117108
118109 /**
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.
129111 *
130- * @param string $dataName
131- * @param int $uniDataFormat
112+ * @param string $name
113+ * @param int $uniquenessFormat
132114 * @return string|null
133115 * @throws TestFrameworkException
134116 */
135- public function getDataByName ($ dataName , $ uniDataFormat )
117+ public function getDataByName ($ name , $ uniquenessFormat )
136118 {
137- if (!$ this ->isValidUniqueDataFormat ($ uniDataFormat )) {
119+ if (!$ this ->isValidUniqueDataFormat ($ uniquenessFormat )) {
138120 throw new TestFrameworkException (
139- sprintf ('Invalid unique data format value: %s \n ' , $ uniDataFormat )
121+ sprintf ('Invalid unique data format value: %s \n ' , $ uniquenessFormat )
140122 );
141123 }
142124
143- $ name = strtolower ($ dataName );
125+ $ name_lower = strtolower ($ name );
144126
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 ];
149131 }
150- return $ this ->formatUniqueData ($ name , $ uniData , $ uniDataFormat );
132+ return $ this ->formatUniqueData ($ name_lower , $ uniquenessData , $ uniquenessFormat );
151133 }
134+
152135 return null ;
153136 }
154137
155138 /**
156139 * Formats and returns data based on given uniqueDataFormat and prefix/suffix.
140+ *
157141 * @param string $name
158142 * @param string $uniqueData
159143 * @param string $uniqueDataFormat
@@ -200,6 +184,7 @@ private function formatUniqueData($name, $uniqueData, $uniqueDataFormat)
200184
201185 /**
202186 * Performs a check that the given uniqueness function exists, throws an exception if it doesn't.
187+ *
203188 * @param string $function
204189 * @param string $uniqueDataFormat
205190 * @return void
@@ -221,13 +206,13 @@ private function checkUniquenessFunctionExists($function, $uniqueDataFormat)
221206 * Function which returns a reference to another entity (e.g. a var with entity="category" field="id" returns as
222207 * category->id)
223208 *
224- * @param string $dataKey
209+ * @param string $key
225210 * @return string|null
226211 */
227- public function getVarReference ($ dataKey )
212+ public function getVarReference ($ key )
228213 {
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 ];
231216 }
232217
233218 return null ;
@@ -237,15 +222,15 @@ public function getVarReference($dataKey)
237222 * This function takes an array of entityTypes indexed by name and a string that represents the type of interest.
238223 * The function returns an array of entityNames relevant to the specified type.
239224 *
240- * @param string $fieldType
225+ * @param string $type
241226 * @return array
242227 */
243- public function getLinkedEntitiesOfType ($ fieldType )
228+ public function getLinkedEntitiesOfType ($ type )
244229 {
245230 $ groupedArray = [];
246231
247232 foreach ($ this ->linkedEntities as $ entityName => $ entityType ) {
248- if ($ entityType == $ fieldType ) {
233+ if ($ entityType == $ type ) {
249234 $ groupedArray [] = $ entityName ;
250235 }
251236 }
0 commit comments