Skip to content

Commit a573628

Browse files
authored
Merge pull request php-webdriver#397 from OndraM/fix/code-fixes
Various codestyle and typehint fixes
2 parents 872685a + 3df0ef7 commit a573628

File tree

10 files changed

+99
-45
lines changed

10 files changed

+99
-45
lines changed

lib/Chrome/ChromeDriver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public static function create(
6363
$connection_timeout_in_ms = null,
6464
$request_timeout_in_ms = null,
6565
$http_proxy = null,
66-
$http_proxy_port = null
66+
$http_proxy_port = null,
67+
DesiredCapabilities $required_capabilities = null
6768
) {
6869
throw new WebDriverException('Please use ChromeDriver::start() instead.');
6970
}

lib/Firefox/FirefoxProfile.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,12 @@ private function installExtension($extension, $profile_dir)
226226
$ext_dir = $profile_dir . '/extensions/' . $matches[1];
227227
mkdir($ext_dir, 0777, true);
228228
$this->extractTo($extension, $ext_dir);
229+
} else {
230+
$this->deleteDirectory($temp_dir);
231+
232+
throw new WebDriverException('Cannot get the extension id from the install manifest.');
229233
}
230234

231-
// clean up
232235
$this->deleteDirectory($temp_dir);
233236

234237
return $ext_dir;

lib/Interactions/WebDriverActions.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Facebook\WebDriver\Interactions\Internal\WebDriverSendKeysAction;
2828
use Facebook\WebDriver\WebDriver;
2929
use Facebook\WebDriver\WebDriverElement;
30+
use Facebook\WebDriver\WebDriverHasInputDevices;
3031

3132
/**
3233
* WebDriver action builder. It implements the builder pattern.
@@ -39,9 +40,9 @@ class WebDriverActions
3940
protected $action;
4041

4142
/**
42-
* @param WebDriver $driver
43+
* @param WebDriverHasInputDevices $driver
4344
*/
44-
public function __construct(WebDriver $driver)
45+
public function __construct(WebDriverHasInputDevices $driver)
4546
{
4647
$this->driver = $driver;
4748
$this->keyboard = $driver->getKeyboard();

lib/Remote/RemoteWebDriver.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
use Facebook\WebDriver\WebDriver;
2121
use Facebook\WebDriver\WebDriverBy;
2222
use Facebook\WebDriver\WebDriverCapabilities;
23-
use Facebook\WebDriver\WebDriverCommandExecutor;
2423
use Facebook\WebDriver\WebDriverElement;
24+
use Facebook\WebDriver\WebDriverHasInputDevices;
2525
use Facebook\WebDriver\WebDriverNavigation;
2626
use Facebook\WebDriver\WebDriverOptions;
2727
use Facebook\WebDriver\WebDriverWait;
2828

29-
class RemoteWebDriver implements WebDriver, JavaScriptExecutor
29+
class RemoteWebDriver implements WebDriver, JavaScriptExecutor, WebDriverHasInputDevices
3030
{
3131
/**
32-
* @var HttpCommandExecutor
32+
* @var HttpCommandExecutor|null
3333
*/
3434
protected $executor;
3535
/**
@@ -507,10 +507,10 @@ protected function newElement($id)
507507
* @deprecated To be removed in the future. Executor should be passed in the constructor.
508508
* @internal
509509
* @codeCoverageIgnore
510-
* @param WebDriverCommandExecutor $executor
510+
* @param HttpCommandExecutor $executor
511511
* @return RemoteWebDriver
512512
*/
513-
public function setCommandExecutor(WebDriverCommandExecutor $executor)
513+
public function setCommandExecutor(HttpCommandExecutor $executor)
514514
{
515515
$this->executor = $executor;
516516

lib/Remote/Service/DriverService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class DriverService
4646
private $environment;
4747

4848
/**
49-
* @var Process
49+
* @var Process|null
5050
*/
5151
private $process;
5252

lib/Support/Events/EventFiringWebDriver.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ public function __construct(WebDriver $driver, WebDriverDispatcher $dispatcher =
5050
$this->dispatcher->setDefaultDriver($this);
5151
}
5252
$this->driver = $driver;
53-
54-
return $this;
5553
}
5654

5755
/**
@@ -105,6 +103,7 @@ public function get($url)
105103
$this->driver->get($url);
106104
} catch (WebDriverException $exception) {
107105
$this->dispatchOnException($exception);
106+
throw $exception;
108107
}
109108
$this->dispatch('afterNavigateTo', $url, $this);
110109

@@ -127,6 +126,7 @@ public function findElements(WebDriverBy $by)
127126
}
128127
} catch (WebDriverException $exception) {
129128
$this->dispatchOnException($exception);
129+
throw $exception;
130130
}
131131

132132
$this->dispatch('afterFindBy', $by, null, $this);
@@ -147,6 +147,7 @@ public function findElement(WebDriverBy $by)
147147
$element = $this->newElement($this->driver->findElement($by));
148148
} catch (WebDriverException $exception) {
149149
$this->dispatchOnException($exception);
150+
throw $exception;
150151
}
151152

152153
$this->dispatch('afterFindBy', $by, null, $this);
@@ -174,6 +175,7 @@ public function executeScript($script, array $arguments = [])
174175
$result = $this->driver->executeScript($script, $arguments);
175176
} catch (WebDriverException $exception) {
176177
$this->dispatchOnException($exception);
178+
throw $exception;
177179
}
178180

179181
$this->dispatch('afterScript', $script, $this);
@@ -200,6 +202,7 @@ public function executeAsyncScript($script, array $arguments = [])
200202
$result = $this->driver->executeAsyncScript($script, $arguments);
201203
} catch (WebDriverException $exception) {
202204
$this->dispatchOnException($exception);
205+
throw $exception;
203206
}
204207
$this->dispatch('afterScript', $script, $this);
205208

@@ -218,6 +221,7 @@ public function close()
218221
return $this;
219222
} catch (WebDriverException $exception) {
220223
$this->dispatchOnException($exception);
224+
throw $exception;
221225
}
222226
}
223227

@@ -231,6 +235,7 @@ public function getCurrentURL()
231235
return $this->driver->getCurrentURL();
232236
} catch (WebDriverException $exception) {
233237
$this->dispatchOnException($exception);
238+
throw $exception;
234239
}
235240
}
236241

@@ -244,6 +249,7 @@ public function getPageSource()
244249
return $this->driver->getPageSource();
245250
} catch (WebDriverException $exception) {
246251
$this->dispatchOnException($exception);
252+
throw $exception;
247253
}
248254
}
249255

@@ -257,6 +263,7 @@ public function getTitle()
257263
return $this->driver->getTitle();
258264
} catch (WebDriverException $exception) {
259265
$this->dispatchOnException($exception);
266+
throw $exception;
260267
}
261268
}
262269

@@ -270,6 +277,7 @@ public function getWindowHandle()
270277
return $this->driver->getWindowHandle();
271278
} catch (WebDriverException $exception) {
272279
$this->dispatchOnException($exception);
280+
throw $exception;
273281
}
274282
}
275283

@@ -283,6 +291,7 @@ public function getWindowHandles()
283291
return $this->driver->getWindowHandles();
284292
} catch (WebDriverException $exception) {
285293
$this->dispatchOnException($exception);
294+
throw $exception;
286295
}
287296
}
288297

@@ -295,6 +304,7 @@ public function quit()
295304
$this->driver->quit();
296305
} catch (WebDriverException $exception) {
297306
$this->dispatchOnException($exception);
307+
throw $exception;
298308
}
299309
}
300310

@@ -309,6 +319,7 @@ public function takeScreenshot($save_as = null)
309319
return $this->driver->takeScreenshot($save_as);
310320
} catch (WebDriverException $exception) {
311321
$this->dispatchOnException($exception);
322+
throw $exception;
312323
}
313324
}
314325

@@ -324,6 +335,7 @@ public function wait($timeout_in_second = 30, $interval_in_millisecond = 250)
324335
return $this->driver->wait($timeout_in_second, $interval_in_millisecond);
325336
} catch (WebDriverException $exception) {
326337
$this->dispatchOnException($exception);
338+
throw $exception;
327339
}
328340
}
329341

@@ -337,6 +349,7 @@ public function manage()
337349
return $this->driver->manage();
338350
} catch (WebDriverException $exception) {
339351
$this->dispatchOnException($exception);
352+
throw $exception;
340353
}
341354
}
342355

@@ -353,6 +366,7 @@ public function navigate()
353366
);
354367
} catch (WebDriverException $exception) {
355368
$this->dispatchOnException($exception);
369+
throw $exception;
356370
}
357371
}
358372

@@ -366,6 +380,7 @@ public function switchTo()
366380
return $this->driver->switchTo();
367381
} catch (WebDriverException $exception) {
368382
$this->dispatchOnException($exception);
383+
throw $exception;
369384
}
370385
}
371386

@@ -379,13 +394,16 @@ public function getTouch()
379394
return $this->driver->getTouch();
380395
} catch (WebDriverException $exception) {
381396
$this->dispatchOnException($exception);
397+
throw $exception;
382398
}
383399
}
384400

385-
private function dispatchOnException($exception)
401+
/**
402+
* @param WebDriverException $exception
403+
*/
404+
private function dispatchOnException(WebDriverException $exception)
386405
{
387406
$this->dispatch('onException', $exception, $this);
388-
throw $exception;
389407
}
390408

391409
public function execute($name, $params)
@@ -394,6 +412,7 @@ public function execute($name, $params)
394412
return $this->driver->execute($name, $params);
395413
} catch (WebDriverException $exception) {
396414
$this->dispatchOnException($exception);
415+
throw $exception;
397416
}
398417
}
399418
}

0 commit comments

Comments
 (0)