@@ -161,7 +161,7 @@ protected function curl($requestMethod, $command, $parameters = null, $extraOpti
161161 $ url .= '/ ' . $ parameters ;
162162 }
163163
164- $ this ->assertNonObjectParameters ($ parameters );
164+ $ this ->assertSerializable ($ parameters );
165165
166166 list ($ rawResult , $ info ) = $ this ->curlService ->execute (
167167 $ requestMethod ,
@@ -184,7 +184,7 @@ protected function curl($requestMethod, $command, $parameters = null, $extraOpti
184184 $ result = json_decode ($ rawResult , true );
185185
186186 if (! empty ($ rawResult ) && $ result === null && json_last_error () != JSON_ERROR_NONE ) {
187- // Legacy webdriver 4xx responses are to be considered // an error and return plaintext
187+ // Legacy webdriver 4xx responses are to be considered a plaintext error
188188 if ($ httpCode >= 400 && $ httpCode <= 499 ) {
189189 throw WebDriverException::factory (
190190 WebDriverException::CURL_EXEC ,
@@ -205,13 +205,9 @@ protected function curl($requestMethod, $command, $parameters = null, $extraOpti
205205 );
206206 }
207207
208- $ value = (is_array ($ result ) && array_key_exists ('value ' , $ result )) ? $ result ['value ' ] : null ;
209- $ message = (is_array ($ result ) && array_key_exists ('message ' , $ result ))
210- ? $ result ['message ' ]
211- : ((is_array ($ value ) && array_key_exists ('message ' , $ value )) ? $ value ['message ' ] : null );
212- $ error = (is_array ($ result ) && array_key_exists ('error ' , $ result ))
213- ? $ result ['error ' ]
214- : ((is_array ($ value ) && array_key_exists ('error ' , $ value )) ? $ value ['error ' ] : null );
208+ $ value = $ this ->offsetGet ('value ' , $ result );
209+ $ message = $ this ->offsetGet ('message ' , $ result ) ?: $ this ->offsetGet ('message ' , $ value );
210+ $ error = $ this ->offsetGet ('error ' , $ result ) ?: $ this ->offsetGet ('error ' , $ value );
215211
216212 // if not success, throw exception
217213 if (isset ($ result ['status ' ]) && (int ) $ result ['status ' ] !== 0 ) {
@@ -228,15 +224,9 @@ protected function curl($requestMethod, $command, $parameters = null, $extraOpti
228224 );
229225 }
230226
231- $ sessionId = isset ($ result ['sessionId ' ])
232- ? $ result ['sessionId ' ]
233- : (isset ($ value ['sessionId ' ])
234- ? $ value ['sessionId ' ]
235- : (isset ($ value ['webdriver.remote.sessionid ' ])
236- ? $ value ['webdriver.remote.sessionid ' ]
237- : null
238- )
239- );
227+ $ sessionId = $ this ->offsetGet ('sessionId ' , $ result )
228+ ?: $ this ->offsetGet ('sessionId ' , $ value )
229+ ?: $ this ->offsetGet ('webdriver.remote.sessionid ' , $ value );
240230
241231 return array (
242232 'value ' => $ value ,
@@ -246,32 +236,6 @@ protected function curl($requestMethod, $command, $parameters = null, $extraOpti
246236 );
247237 }
248238
249- /**
250- * @param mixed $parameters
251- */
252- private function assertNonObjectParameters ($ parameters )
253- {
254- if ($ parameters === null || is_scalar ($ parameters )) {
255- return ;
256- }
257-
258- if (is_array ($ parameters )) {
259- foreach ($ parameters as $ value ) {
260- $ this ->assertNonObjectParameters ($ value );
261- }
262-
263- return ;
264- }
265-
266- throw WebDriverException::factory (
267- WebDriverException::UNEXPECTED_PARAMETERS ,
268- sprintf (
269- "Unable to serialize non-scalar type %s " ,
270- is_object ($ parameters ) ? get_class ($ parameters ) : gettype ($ parameters )
271- )
272- );
273- }
274-
275239 /**
276240 * Magic method that maps calls to class methods to execute WebDriver commands
277241 *
@@ -323,6 +287,47 @@ public function __call($name, $arguments)
323287 return $ result ['value ' ];
324288 }
325289
290+ /**
291+ * Sanity check
292+ *
293+ * @param mixed $parameters
294+ */
295+ private function assertSerializable ($ parameters )
296+ {
297+ if ($ parameters === null || is_scalar ($ parameters )) {
298+ return ;
299+ }
300+
301+ if (is_array ($ parameters )) {
302+ foreach ($ parameters as $ value ) {
303+ $ this ->assertSerializable ($ value );
304+ }
305+
306+ return ;
307+ }
308+
309+ throw WebDriverException::factory (
310+ WebDriverException::UNEXPECTED_PARAMETERS ,
311+ sprintf (
312+ "Unable to serialize non-scalar type %s " ,
313+ is_object ($ parameters ) ? get_class ($ parameters ) : gettype ($ parameters )
314+ )
315+ );
316+ }
317+
318+ /**
319+ * Extract value from result
320+ *
321+ * @param string $key
322+ * @param mixed $result
323+ *
324+ * @return string|null
325+ */
326+ private function offsetGet ($ key , $ result )
327+ {
328+ return (is_array ($ result ) && array_key_exists ($ key , $ result )) ? $ result [$ key ] : null ;
329+ }
330+
326331 /**
327332 * Get default HTTP request method for a given WebDriver command
328333 *
0 commit comments