Driver_Phantomjs   B
last analyzed

Complexity

Total Complexity 52

Size/Duplication

Total Lines 403
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 97.3%

Importance

Changes 0
Metric Value
wmc 52
lcom 1
cbo 2
dl 0
loc 403
ccs 108
cts 111
cp 0.973
rs 7.44
c 0
b 0
f 0

29 Methods

Rating   Name   Duplication   Size   Complexity  
A tag_name() 0 4 1
A all() 0 4 2
A clear() 0 4 1
A content() 0 4 1
A attribute() 0 4 1
A text() 0 6 1
A value() 0 4 1
A is_visible() 0 4 1
A is_selected() 0 4 1
A is_checked() 0 4 1
A select_option() 0 4 1
A click() 0 4 1
A current_path() 0 6 2
A current_url() 0 4 1
A next_query() 0 4 1
A is_page_active() 0 4 1
A javascript_errors() 0 4 1
A javascript_messages() 0 4 1
A screenshot() 0 4 1
A cookies() 0 4 1
A base_url() 0 9 2
A connection() 0 16 3
A __destruct() 0 7 3
A html() 0 7 2
B set() 0 29 7
A visit() 0 17 3
A user_agent() 0 10 3
A execute() 0 7 1
A cookie() 0 12 6

How to fix   Complexity   

Complex Class

Complex classes like Driver_Phantomjs often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Driver_Phantomjs, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Openbuildings\Spiderling;
4
5
/**
6
 * Use phantomjs to load urls.
7
 * Has Javascript
8
 *
9
 * @package    Openbuildings\Spiderling
10
 * @author     Ivan Kerin
11
 * @copyright  (c) 2013 OpenBuildings Ltd.
12
 * @license    http://spdx.org/licenses/BSD-3-Clause
13
 */
14
class Driver_Phantomjs extends Driver {
15
16
	/**
17
	 * Driver name
18
	 * @var string
19
	 */
20
	public $name = 'phantomjs';
21
22
	/**
23
	 * Array containing parameters to be added on the next request
24
	 * @var array
25
	 */
26
	public $_next_query = array();
27
28
	/**
29
	 * User agent string cache
30
	 * @var string
31
	 */
32
	protected $_user_agent;
33
34
	/**
35
	 * Variable holding the current Driver_Phantomjs_Connection
36
	 * @var Driver_Phantomjs_Connection
37
	 */
38
	protected $_connection;
39
40
	/**
41
	 * The base URL, to be prefixed on each request
42
	 * @var string
43
	 */
44
	protected $_base_url = '';
45
46
	/**
47
	 * Getter / Setter of the base_url, that will be prefixed on each request
48
	 * @param  string $base_url
49
	 * @return string|Driver_PHantomjs
50
	 */
51 3
	public function base_url($base_url = NULL)
52
	{
53 3
		if ($base_url !== NULL)
54
		{
55 1
			$this->_base_url = (string) $base_url;
56 1
			return $this;
57
		}
58 3
		return $this->_base_url;
59
	}
60
61
	/**
62
	 * Getter / Setter of the Driver_Phantomjs_Connection object.
63
	 * Use this to customize the connection, otherwise a default one on a random port will be used
64
	 *
65
	 * @param  Driver_Phantomjs_Connection $connection
66
	 * @return Driver_Phantomjs_Connection|Driver_Phantomjs
67
	 */
68 13
	public function connection(Driver_Phantomjs_Connection $connection = NULL)
69
	{
70 13
		if ($connection !== NULL)
71
		{
72 1
			$this->_connection = $connection;
73 1
			return $this;
74
		}
75
76 13
		if ( ! $this->_connection)
77
		{
78 1
			$this->_connection = new Driver_Phantomjs_Connection();
79 1
			$this->_connection->start();
80
		}
81
82 13
		return $this->_connection;
83
	}
84
85
	/**
86
	 * If a connection has been started, stop it
87
	 */
88 2
	public function __destruct()
89
	{
90 2
		if ($this->_connection AND $this->_connection->is_started())
91
		{
92 1
			$this->_connection->stop();
93
		}
94 2
	}
95
96
	/**
97
	 * Clear the connection by deleting all cookies
98
	 */
99 1
	public function clear()
100
	{
101 1
		$this->connection()->delete('cookies');
0 ignored issues
show
Bug introduced by
The method delete does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
102 1
	}
103
104
	/**
105
	 * Getter of the raw content html, this driver does not allow "setting"
106
	 *
107
	 * @param  string $content
108
	 * @return string
109
	 */
110 1
	public function content($content = NULL)
111
	{
112 1
		return $this->connection()->get('source');
0 ignored issues
show
Bug introduced by
The method get does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
113
	}
114
115
	/**
116
	 * NODE GETTERS
117
	 * =====================================
118
	 */
119
120
	/**
121
	 * Get the tag name of a Node with id. e.g. DIV, SPAN ...
122
	 * @param  string $id
123
	 * @return string
124
	 */
125 2
	public function tag_name($id)
126
	{
127 2
		return $this->connection()->get("element/$id/name");
0 ignored issues
show
Bug introduced by
The method get does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
128
	}
129
130
	/**
131
	 * Get the attribute of a Node with id. If the attribute does not exist, returns NULL
132
	 * @param  string $id
133
	 * @param  string $name
134
	 * @return string
135
	 */
136 2
	public function attribute($id, $name)
137
	{
138 2
		return $this->connection()->get("element/$id/attribute/$name");
0 ignored issues
show
Bug introduced by
The method get does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
139
	}
140
141
	/**
142
	 * Return the raw html of a Node with id, along with all of its children.
143
	 * @param  string $id
144
	 * @return string
145
	 */
146 1
	public function html($id)
147
	{
148 1
		if ($id === NULL)
149
			return $this->content();
150
151 1
		return $this->connection()->get("element/$id/html");
0 ignored issues
show
Bug introduced by
The method get does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
152
	}
153
154
	/**
155
	 * Return the text of a Node with id, with all the spaces collapsed, similar to browser rendering.
156
	 * @param  string $id
157
	 * @return string
158
	 */
159 2
	public function text($id)
160
	{
161 2
		$text = $this->connection()->get("element/$id/text");
0 ignored issues
show
Bug introduced by
The method get does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
162 2
		$text = preg_replace('/[ \s\f\n\r\t\v ]+/u', ' ', $text);
163 2
		return trim($text);
164
	}
165
166
	/**
167
	 * Return the value of a Node of a form element, e.g. INPUT, TEXTAREA or SELECT
168
	 * @param  string $id
169
	 * @return string
170
	 */
171 2
	public function value($id)
172
	{
173 2
		return $this->connection()->get("element/$id/value");
0 ignored issues
show
Bug introduced by
The method get does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
174
	}
175
176
	/**
177
	 * Check if a Node with id is visible.
178
	 * @param  string  $id
179
	 * @return boolean
180
	 */
181 1
	public function is_visible($id)
182
	{
183 1
		return $this->connection()->get("element/$id/visible");
0 ignored issues
show
Bug introduced by
The method get does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
184
	}
185
186
	/**
187
	 * Check if a Node with id of an option element is selected
188
	 * @param  string  $id
189
	 * @return boolean
190
	 */
191 2
	public function is_selected($id)
192
	{
193 2
		return $this->connection()->get("element/$id/selected");
0 ignored issues
show
Bug introduced by
The method get does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
194
	}
195
196
	/**
197
	 * Check if a Node with id of an input element (radio or checkbox) is checked
198
	 * @param  string  $id
199
	 * @return boolean
200
	 */
201 1
	public function is_checked($id)
202
	{
203 1
		return $this->connection()->get("element/$id/checked");
0 ignored issues
show
Bug introduced by
The method get does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
204
	}
205
206
	/**
207
	 * Set the value of a Node with id of a form element
208
	 * @param string $id
209
	 * @param string $value
210
	 */
211 1
	public function set($id, $value)
212
	{
213 1
		$tag_name = $this->tag_name($id);
214
215 1
		if ($tag_name == 'textarea')
216
		{
217 1
			$this->connection()->post("element/$id/value", array('value' => $value));
0 ignored issues
show
Bug introduced by
The method post does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
218
		}
219 1
		elseif ($tag_name == 'input')
220
		{
221 1
			$type = $this->attribute($id, 'type');
222 1
			if ($type == 'checkbox' OR $type == 'radio')
223
			{
224 1
				$this->connection()->post("element/$id/click", array());
225
			}
226 1
			elseif ($type == 'file')
227
			{
228 1
				$this->connection()->post("element/$id/upload", array('value' => $value));
229
			}
230
			else
231
			{
232 1
				$this->connection()->post("element/$id/value", array('value' => $value));
233
			}
234
		}
235 1
		elseif ($tag_name == 'option')
236
		{
237 1
			$this->connection()->post("element/$id/selected", array('value' => $value));
238
		}
239 1
	}
240
241
	/**
242
	 * Set the option value that is selected of a Node of a select element
243
	 * @param  string $id
244
	 * @param  string $value
245
	 */
246 1
	public function select_option($id, $value)
247
	{
248 1
		$this->connection()->post("element/$id/selected", array('value' => $value));
0 ignored issues
show
Bug introduced by
The method post does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
249 1
	}
250
251
	/**
252
	 * Click on a Node with id, triggering a link or form submit
253
	 * @param  string $id
254
	 * @throws Exception_Driver If not a clickable element
255
	 */
256 1
	public function click($id)
257
	{
258 1
		$this->connection()->post("element/$id/click", array());
0 ignored issues
show
Bug introduced by
The method post does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
259 1
	}
260
261
	/**
262
	 * Go to a given url address, use next_query along with the provided query array
263
	 * @param  string $uri
264
	 * @param  array  $query
265
	 */
266 2
	public function visit($uri, array $query = array())
267
	{
268 2
		$query = array_merge((array) $this->_next_query, (array) $query);
269
270 2
		$this->_next_query = NULL;
0 ignored issues
show
Documentation Bug introduced by
It seems like NULL of type null is incompatible with the declared type array of property $_next_query.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
271
272
		// Check for implicit query string
273 2
		if (strpos($uri, '?') !== FALSE)
274
		{
275
			$query = array_merge(self::extract_query_from_uri($uri), $query);
276
			$uri = substr($uri, 0, strpos($uri, '?'));
277
		}
278
279 2
		$url = $this->base_url().$uri.($query ? '?'.http_build_query($query) : '');
280
281 2
		$this->connection()->post('url', array('value' => $url));
0 ignored issues
show
Bug introduced by
The method post does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
282 2
	}
283
284
	/**
285
	 * Get the current path (without host and protocol)
286
	 * @return string
287
	 */
288 1
	public function current_path()
289
	{
290 1
		$url = parse_url($this->connection()->get('url'));
0 ignored issues
show
Bug introduced by
The method get does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
291
292 1
		return $url['path'].(isset($url['query']) ? '?'.$url['query'] : '');
293
	}
294
295
	/**
296
	 * Get the current url
297
	 * @return string
298
	 */
299 2
	public function current_url()
300
	{
301 2
		return urldecode($this->connection()->get('url'));
0 ignored issues
show
Bug introduced by
The method get does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
302
	}
303
304
	/**
305
	 * Find all ids of a given XPath
306
	 * @param  string $xpath
307
	 * @param  string $parent id of the parent node
308
	 * @return array
309
	 */
310 7
	public function all($xpath, $parent = NULL)
311
	{
312 7
		return $this->connection()->post(($parent === NULL ? '' : 'element/'.$parent.'/').'elements', array('value' => '.'.$xpath));
0 ignored issues
show
Bug introduced by
The method post does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
313
	}
314
315
	/**
316
	 * Setter for the next_query variable, to be added to the next visit's query
317
	 * @param  array  $query
318
	 */
319 1
	public function next_query(array $query)
320
	{
321 1
		$this->_next_query = $query;
322 1
	}
323
324
	/**
325
	 * Check if a connection is active
326
	 * @return boolean
327
	 */
328 1
	public function is_page_active()
329
	{
330 1
		return (bool) $this->_connection;
331
	}
332
333
	/**
334
	 * Return all javascript errors for the current page
335
	 * @return array
336
	 */
337 1
	public function javascript_errors()
338
	{
339 1
		return $this->connection()->get('errors', array());
0 ignored issues
show
Unused Code introduced by
The call to Driver_Phantomjs_Connection::get() has too many arguments starting with array().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Bug introduced by
The method get does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
340
	}
341
342
	/**
343
	 * Return all console messages for the current page
344
	 * @return array
345
	 */
346 1
	public function javascript_messages()
347
	{
348 1
		return $this->connection()->get('messages', array());
0 ignored issues
show
Unused Code introduced by
The call to Driver_Phantomjs_Connection::get() has too many arguments starting with array().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Bug introduced by
The method get does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
349
	}
350
351
	/**
352
	 * Do a screenshot of the current page into a file
353
	 * @param  string $file
354
	 */
355 1
	public function screenshot($file)
356
	{
357 1
		$this->connection()->post('screenshot', array('value' => $file));
0 ignored issues
show
Bug introduced by
The method post does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
358 1
	}
359
360
	/**
361
	 * Get the current user agent
362
	 * @return string
363
	 */
364 1
	public function user_agent()
365
	{
366 1
		if ( ! $this->_user_agent)
367
		{
368 1
			$settings = $this->connection()->get('settings');
0 ignored issues
show
Bug introduced by
The method get does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
369 1
			$this->_user_agent = isset($settings['userAgent']) ? $settings['userAgent'] : NULL;
370
		}
371
372 1
		return $this->_user_agent;
373
	}
374
375
	/**
376
	 * Execute raw javascript. it will be executed in the context of a given node ('this' will point to the node) and the return of the script will be the return of this method
377
	 * @param  string $id
378
	 * @param  string $script
379
	 * @return mixed
380
	 */
381 2
	public function execute($id, $script)
382
	{
383 2
		return $this->connection()->post('execute', array(
0 ignored issues
show
Bug introduced by
The method post does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
384 2
			'value' => $script,
385 2
			'id' => $id,
386
		));
387
	}
388
389
	/**
390
	 * Return all the current cookies
391
	 * @return array
392
	 */
393 1
	public function cookies()
394
	{
395 1
		return $this->connection()->get('cookies');
0 ignored issues
show
Bug introduced by
The method get does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
396
	}
397
398
	/**
399
	 * Set a cookie. Use parameters to set "expires", "path", "domain", "secure" and "httponly"
400
	 * @param  string $name
401
	 * @param  mixed $value
402
	 * @param  array  $parameters
403
	 */
404 1
	public function cookie($name, $value, array $parameters = array())
405
	{
406 1
		$this->connection()->post('cookie', array(
0 ignored issues
show
Bug introduced by
The method post does only exist in Openbuildings\Spiderling...er_Phantomjs_Connection, but not in Openbuildings\Spiderling\Driver_Phantomjs.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
407 1
			'name' => $name,
408 1
			'value' => $value,
409 1
			'expires' => isset($parameters['expires']) ? $parameters['expires'] : time() + 86400,
410 1
			'path' => isset($parameters['path']) ? $parameters['path'] : '/',
411 1
			'domain' => isset($parameters['domain']) ? $parameters['domain'] : NULL,
412 1
			'secure' => isset($parameters['secure']) ? $parameters['secure'] : FALSE,
413 1
			'httponly' => isset($parameters['httponly']) ? $parameters['httponly'] : FALSE,
414
		));
415 1
	}
416
}
417