Completed
Pull Request — master (#20)
by Haralan
11:12 queued 09:14
created

Exception_Selenium   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 0
cbo 1
dl 0
loc 68
ccs 0
cts 6
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
1
<?php
2
3
namespace Openbuildings\Spiderling;
4
5
/**
6
 * @package    Openbuildings\Spiderling
7
 * @author     Ivan Kerin
8
 * @copyright  (c) 2013 OpenBuildings Ltd.
9
 * @license    http://spdx.org/licenses/BSD-3-Clause
10
 */
11
class Exception_Selenium extends Exception {
12
13
	protected static $names = array(
14
		6 => 'NoSuchDriver',
15
		7 => 'NoSuchElement',
16
		8 => 'NoSuchFrame',
17
		9 => 'UnknownCommand',
18
		10 => 'StaleElementReference',
19
		11 => 'ElementNotVisible',
20
		12 => 'InvalidElementState',
21
		13 => 'UnknownError',
22
		15 => 'ElementIsNotSelectable',
23
		17 => 'JavaScriptError',
24
		19 => 'XPathLookupError',
25
		21 => 'Timeout',
26
		23 => 'NoSuchWindow',
27
		24 => 'InvalidCookieDomain',
28
		25 => 'UnableToSetCookie',
29
		26 => 'UnexpectedAlertOpen',
30
		27 => 'NoAlertOpenError',
31
		28 => 'ScriptTimeout',
32
		29 => 'InvalidElementCoordinates',
33
		30 => 'IMENotAvailable',
34
		31 => 'IMEEngineActivationFailed',
35
		32 => 'InvalidSelector',
36
		33 => 'SessionNotCreatedException',
37
		34 => 'MoveTargetOutOfBounds',
38
	);
39
40
	protected static $messages = array(
41
		6 => 'A session is either terminated or not started',
42
		7 => 'An element could not be located on the page using the given search parameters.',
43
		8 => 'A request to switch to a frame could not be satisfied because the frame could not be found.',
44
		9 => 'The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource.',
45
		10 => 'An element command failed because the referenced element is no longer attached to the DOM.',
46
		11 => 'An element command could not be completed because the element is not visible on the page.',
47
		12 => 'An element command could not be completed because the element is in an invalid state (e.g. attempting to click a disabled element).',
48
		13 => 'An unknown server-side error occurred while processing the command.',
49
		15 => 'An attempt was made to select an element that cannot be selected.',
50
		17 => 'An error occurred while executing user supplied JavaScript.',
51
		19 => 'An error occurred while searching for an element by XPath.',
52
		21 => 'An operation did not complete before its timeout expired.',
53
		23 => 'A request to switch to a different window could not be satisfied because the window could not be found.',
54
		24 => 'An illegal attempt was made to set a cookie under a different domain than the current page.',
55
		25 => 'A request to set a cookie\'s value could not be satisfied.',
56
		26 => 'A modal dialog was open, blocking this operation',
57
		27 => 'An attempt was made to operate on a modal dialog when one was not open.',
58
		28 => 'A script did not complete before its timeout expired.',
59
		29 => 'The coordinates provided to an interactions operation are invalid.',
60
		30 => 'IME was not available.',
61
		31 => 'An IME engine could not be started.',
62
		32 => 'Argument was an invalid selector (e.g. XPath/CSS).',
63
		33 => 'A new session could not be created.',
64
		34 => 'Target provided for a move action is out of bounds.',
65
	);
66
67
	public $name;
68
69
	public function __construct($code, \Exception $previous = NULL)
70
	{
71
		$message = isset(self::$messages[$code]) ? self::$messages[$code] : 'Unknown Error';
72
		$this->name = isset(self::$names[$code]) ? self::$names[$code] : 'UnknownError';
73
74
		parent::__construct($this->name.': '.$message, array(), $previous);
75
76
		$this->code = $code;
77
	}
78
}
79