@@ -120,7 +120,7 @@ protected function curl($requestMethod, $command, $parameters = null, $extraOpti
120120 $ url .= '/ ' . $ parameters ;
121121 }
122122
123- $ this ->assertNonObjectParameters ($ parameters );
123+ $ this ->assertSerializable ($ parameters );
124124
125125 list ($ rawResult , $ info ) = ServiceFactory::getInstance ()->getService ('service.curl ' )->execute ($ requestMethod , $ url , $ parameters , $ extraOptions );
126126
@@ -135,8 +135,8 @@ protected function curl($requestMethod, $command, $parameters = null, $extraOpti
135135
136136 $ result = json_decode ($ rawResult , true );
137137
138- if (!empty ($ rawResult ) && $ result === null && json_last_error () != JSON_ERROR_NONE ) {
139- // Legacy webdriver 4xx responses are to be considered // an error and return plaintext
138+ if (! empty ($ rawResult ) && $ result === null && json_last_error () != JSON_ERROR_NONE ) {
139+ // Legacy webdriver 4xx responses are to be considered a plaintext error
140140 if ($ httpCode >= 400 && $ httpCode <= 499 ) {
141141 throw WebDriverException::factory (
142142 WebDriverException::CURL_EXEC ,
@@ -157,13 +157,9 @@ protected function curl($requestMethod, $command, $parameters = null, $extraOpti
157157 );
158158 }
159159
160- $ value = (is_array ($ result ) && array_key_exists ('value ' , $ result )) ? $ result ['value ' ] : null ;
161- $ message = (is_array ($ result ) && array_key_exists ('message ' , $ result ))
162- ? $ result ['message ' ]
163- : ((is_array ($ value ) && array_key_exists ('message ' , $ value )) ? $ value ['message ' ] : null );
164- $ error = (is_array ($ result ) && array_key_exists ('error ' , $ result ))
165- ? $ result ['error ' ]
166- : ((is_array ($ value ) && array_key_exists ('error ' , $ value )) ? $ value ['error ' ] : null );
160+ $ value = $ this ->offsetGet ('value ' , $ result );
161+ $ message = $ this ->offsetGet ('message ' , $ result ) ?: $ this ->offsetGet ('message ' , $ value );
162+ $ error = $ this ->offsetGet ('error ' , $ result ) ?: $ this ->offsetGet ('error ' , $ value );
167163
168164 // if not success, throw exception
169165 if (isset ($ result ['status ' ]) && (int ) $ result ['status ' ] !== 0 ) {
@@ -180,15 +176,9 @@ protected function curl($requestMethod, $command, $parameters = null, $extraOpti
180176 );
181177 }
182178
183- $ sessionId = isset ($ result ['sessionId ' ])
184- ? $ result ['sessionId ' ]
185- : (isset ($ value ['sessionId ' ])
186- ? $ value ['sessionId ' ]
187- : (isset ($ value ['webdriver.remote.sessionid ' ])
188- ? $ value ['webdriver.remote.sessionid ' ]
189- : null
190- )
191- );
179+ $ sessionId = $ this ->offsetGet ('sessionId ' , $ result )
180+ ?: $ this ->offsetGet ('sessionId ' , $ value )
181+ ?: $ this ->offsetGet ('webdriver.remote.sessionid ' , $ value );
192182
193183 return array (
194184 'value ' => $ value ,
@@ -198,32 +188,6 @@ protected function curl($requestMethod, $command, $parameters = null, $extraOpti
198188 );
199189 }
200190
201- /**
202- * @param mixed $parameters
203- */
204- private function assertNonObjectParameters ($ parameters )
205- {
206- if ($ parameters === null || is_scalar ($ parameters )) {
207- return ;
208- }
209-
210- if (is_array ($ parameters )) {
211- foreach ($ parameters as $ value ) {
212- $ this ->assertNonObjectParameters ($ value );
213- }
214-
215- return ;
216- }
217-
218- throw WebDriverException::factory (
219- WebDriverException::UNEXPECTED_PARAMETERS ,
220- sprintf (
221- "Unable to serialize non-scalar type %s " ,
222- is_object ($ parameters ) ? get_class ($ parameters ) : gettype ($ parameters )
223- )
224- );
225- }
226-
227191 /**
228192 * Magic method that maps calls to class methods to execute WebDriver commands
229193 *
@@ -273,6 +237,47 @@ public function __call($name, $arguments)
273237 return $ result ['value ' ];
274238 }
275239
240+ /**
241+ * Sanity check
242+ *
243+ * @param mixed $parameters
244+ */
245+ private function assertSerializable ($ parameters )
246+ {
247+ if ($ parameters === null || is_scalar ($ parameters )) {
248+ return ;
249+ }
250+
251+ if (is_array ($ parameters )) {
252+ foreach ($ parameters as $ value ) {
253+ $ this ->assertSerializable ($ value );
254+ }
255+
256+ return ;
257+ }
258+
259+ throw WebDriverException::factory (
260+ WebDriverException::UNEXPECTED_PARAMETERS ,
261+ sprintf (
262+ "Unable to serialize non-scalar type %s " ,
263+ is_object ($ parameters ) ? get_class ($ parameters ) : gettype ($ parameters )
264+ )
265+ );
266+ }
267+
268+ /**
269+ * Extract value from result
270+ *
271+ * @param string $key
272+ * @param mixed $result
273+ *
274+ * @return string|null
275+ */
276+ private function offsetGet ($ key , $ result )
277+ {
278+ return (is_array ($ result ) && array_key_exists ($ key , $ result )) ? $ result [$ key ] : null ;
279+ }
280+
276281 /**
277282 * Get default HTTP request method for a given WebDriver command
278283 *
0 commit comments