Issues (1066)

Security Analysis    7 potential vulnerabilities

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting (1)
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection (3)
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection (3)
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Plugin/WebBrowser.php (37 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace PhpQuery\Plugin;
3
4
use PhpQuery\PhpQuery;
5
/**
6
 * WebBrowser plugin.
7
 *
8
 */
9
class WebBrowser {
10
	/**
11
	 * Limit binded methods to specified ones.
12
	 *
13
	 * @var array
14
	 */
15
	public static $PhpQueryMethods = null;
16
17
    /**
18
     * Enter description here...
19
     *
20
     * @param \PhpQuery\PhpQueryObject $self
21
     * @param null                     $callback
22
     * @param null                     $location
23
     * @throws \Exception
24
     * @todo support 'reset' event
25
     */
26
	public static function WebBrowser($self, $callback = null, $location = null) {
0 ignored issues
show
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
27
		$self = $self->_clone()->toRoot();
28
		$location = $location
29
			? $location
30
			// TODO use document.location
31
			: $self->document->xhr->getUri(true);
32
		// FIXME tmp
33
		$self->document->WebBrowserCallback = $callback;
34
		if (! $location)
35
			throw new \Exception('Location needed to activate WebBrowser plugin !');
36
		else {
37
			$self->bind('click', array($location, $callback), array('\PhpQuery\Plugin\UtilWebBrowser', 'hadleClick'));
38
			$self->bind('submit', array($location, $callback), array('\PhpQuery\Plugin\UtilWebBrowser', 'handleSubmit'));
39
		}
40
	}
41
	public static function browser($self, $callback = null, $location = null) {
42
		return $self->WebBrowser($callback, $location);
43
	}
44
	public static function downloadTo($self, $dir = null, $filename = null) {
45
		$url = null;
46
		if ($self->is('a[href]'))
47
			$url = $self->attr('href');
48
		else if ($self->find('a')->length)
49
			$url = $self->find('a')->attr('href');
50
		if ($url) {
51
			$url = resolve_url($self->document->location, $url);
52
			if (! $dir)
53
				$dir = getcwd();
54
			// TODO resolv name from response headers
55
			if (! $filename) {
56
				$matches = null;
57
				preg_match('@/([^/]+)$@', $url, $matches);
58
				$filename = $matches[1];
59
			}
60
			//print $url;
61
			$path = rtrim($dir, '/').'/'.$filename;
62
			PhpQuery::debug("Requesting download of $url\n");
63
			// TODO use AJAX instead of file_get_contents
64
			file_put_contents($path, file_get_contents($url));
65
		}
66
		return $self;
67
	}
68
69
    /**
70
     * Method changing browser location.
71
     * Fires callback registered with WebBrowser(), if any.
72
     * @param $self
73
     * @param $url
74
     * @return bool
75
     */
76 View Code Duplication
	public static function location($self, $url = null) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
		// TODO if ! $url return actual location ???
0 ignored issues
show
Unused Code Comprehensibility introduced by
39% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
78
		$xhr = isset($self->document->xhr)
79
			? $self->document->xhr
80
			: null;
81
		$xhr = PhpQuery::ajax(array(
82
			'url' => $url,
83
		), $xhr);
84
		$return = false;
85
		if ($xhr->getLastResponse()->isSuccessful()) {
86
			$return = \PhpQuery\Plugin\UtilWebBrowser::browserReceive($xhr);
87
			if (isset($self->document->WebBrowserCallback))
88
				PhpQuery::callbackRun(
89
					$self->document->WebBrowserCallback,
90
					array($return)
91
				);
92
		}
93
		return $return;
94
	}
95
        
96
        
97 View Code Duplication
        public static function download($self, $url = null) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
98
            $xhr = isset($self->document->xhr)
99
			? $self->document->xhr
100
			: null;
101
		$xhr = PhpQuery::ajax(array(
102
			'url' => $url,
103
		), $xhr);
104
		$return = false;
105
		if ($xhr->getLastResponse()->isSuccessful()) {
106
			$return = \PhpQuery\Plugin\UtilWebBrowser::browserDownload($xhr);
107
			if (isset($self->document->WebBrowserCallback))
108
				PhpQuery::callbackRun(
109
					$self->document->WebBrowserCallback,
110
					array($return)
111
				);
112
		}
113
		return $return;
114
        }
115
}
116
class UtilWebBrowser {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
117
    /**
118
     *
119
     * @param $url
120
     * @param $callback
121
     * @param $param1
122
     * @param $param2
123
     * @param $param3
124
     * @throws \Exception
125
     * @return \Zend_Http_Client
126
     */
127 View Code Duplication
	public static function browserGet($url, $callback,
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
128
		$param1 = null, $param2 = null, $param3 = null) {
0 ignored issues
show
The parameter $param1 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $param2 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $param3 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
129
		PhpQuery::debug("[WebBrowser] GET: $url");
130
		self::authorizeHost($url);
131
		$xhr = PhpQuery::ajax(array(
132
			'type' => 'GET',
133
			'url' => $url,
134
			'dataType' => 'html',
135
		));
136
		$paramStructure = null;
137
		if (func_num_args() > 2) {
138
			$paramStructure = func_get_args();
139
			$paramStructure = array_slice($paramStructure, 2);
140
		}
141
		if ($xhr->getLastResponse()->isSuccessful()) {
142
			PhpQuery::callbackRun($callback,
143
				array(self::browserReceive($xhr)->WebBrowser()),
144
				$paramStructure
145
			);
146
//			PhpQuery::callbackRun($callback, array(
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
147
//				self::browserReceive($xhr)//->WebBrowser($callback)
148
//			));
149
			return $xhr;
150
		} else {
151
			throw new \Exception("[WebBrowser] GET request failed; url: $url");
152
		}
153
	}
154
	/**
155
	 *
156
	 * @param $url
157
	 * @param $data
158
	 * @param $callback
159
	 * @param $param1
160
	 * @param $param2
161
	 * @param $param3
162
	 * @return \Zend_Http_Client
163
	 */
164 View Code Duplication
	public static function browserPost($url, $data, $callback,
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
165
		$param1 = null, $param2 = null, $param3 = null) {
0 ignored issues
show
The parameter $param1 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $param2 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $param3 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
166
		self::authorizeHost($url);
167
		$xhr = PhpQuery::ajax(array(
168
			'type' => 'POST',
169
			'url' => $url,
170
			'dataType' => 'html',
171
			'data' => $data,
172
		));
173
		$paramStructure = null;
174
		if (func_num_args() > 3) {
175
			$paramStructure = func_get_args();
176
			$paramStructure = array_slice($paramStructure, 3);
177
		}
178
		if ($xhr->getLastResponse()->isSuccessful()) {
179
			PhpQuery::callbackRun($callback,
180
				array(self::browserReceive($xhr)->WebBrowser()),
181
				$paramStructure
182
			);
183
//			PhpQuery::callbackRun($callback, array(
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
184
//				self::browserReceive($xhr)//->WebBrowser($callback)
185
//			));
186
			return $xhr;
187
		} else
188
			return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by PhpQuery\Plugin\UtilWebBrowser::browserPost of type Zend_Http_Client.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
189
	}
190
	/**
191
	 *
192
	 * @param $ajaxSettings
193
	 * @param $callback
194
	 * @param $param1
195
	 * @param $param2
196
	 * @param $param3
197
	 * @return Zend_Http_Client
198
	 */
199
	public static function browser($ajaxSettings, $callback,
200
		$param1 = null, $param2 = null, $param3 = null) {
0 ignored issues
show
The parameter $param1 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $param2 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $param3 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
201
		self::authorizeHost($ajaxSettings['url']);
202
		$xhr = PhpQuery::ajax(
203
			self::ajaxSettingsPrepare($ajaxSettings)
204
		);
205
		$paramStructure = null;
206
		if (func_num_args() > 2) {
207
			$paramStructure = func_get_args();
208
			$paramStructure = array_slice($paramStructure, 2);
209
		}
210
		if ($xhr->getLastResponse()->isSuccessful()) {
211
			PhpQuery::callbackRun($callback,
212
				array(self::browserReceive($xhr)->WebBrowser()),
213
				$paramStructure
214
			);
215
//			PhpQuery::callbackRun($callback, array(
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
216
//				self::browserReceive($xhr)//->WebBrowser($callback)
217
//			));
218
			return $xhr;
219
		} else
220
			return false;
221
	}
222
	protected static function authorizeHost($url) {
223
		$host = parse_url($url, PHP_URL_HOST);
224
		if ($host)
0 ignored issues
show
Bug Best Practice introduced by
The expression $host of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
225
			PhpQuery::ajaxAllowHost($host);
226
	}
227
	protected static function ajaxSettingsPrepare($settings) {
228
		unset($settings['success']);
229
		unset($settings['error']);
230
		return $settings;
231
	}
232
	/**
233
	 * @param \Zend_Http_Client $xhr
234
	 */
235
	public static function browserReceive($xhr) {
236
		PhpQuery::debug("[WebBrowser] Received from ".$xhr->getUri(true));
237
		// TODO handle meta redirects
238
		$body = $xhr->getLastResponse()->getBody();
239
240
		// XXX error ???
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
241
		if (strpos($body, '<!doctype html>') !== false) {
242
			$body = '<html>'
243
				.str_replace('<!doctype html>', '', $body)
244
				.'</html>';
245
		}
246
		$pq = PhpQuery::newDocument($body);
247
		$pq->document->xhr = $xhr;
248
		$pq->document->location = $xhr->getUri(true);
249
		$refresh = $pq->find('meta[http-equiv=refresh]')
250
			->add('meta[http-equiv=Refresh]');
251
		if ($refresh->size()) {
252
//			print htmlspecialchars(var_export($xhr->getCookieJar()->getAllCookies(), true));
0 ignored issues
show
Unused Code Comprehensibility introduced by
68% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
253
//			print htmlspecialchars(var_export($xhr->getLastResponse()->getHeader('Set-Cookie'), true));
254
			PhpQuery::debug("Meta redirect... '{$refresh->attr('content')}'\n");
255
			// there is a refresh, so get the new url
256
			$content = $refresh->attr('content');
257
			$urlRefresh = substr($content, strpos($content, '=')+1);
258
			$urlRefresh = trim($urlRefresh, '\'"');
259
			// XXX not secure ?!
260
			PhpQuery::ajaxAllowURL($urlRefresh);
261
//			$urlRefresh = urldecode($urlRefresh);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
262
			// make ajax call, passing last $xhr object to preserve important stuff
263
			$xhr = PhpQuery::ajax(array(
264
				'type' => 'GET',
265
				'url' => $urlRefresh,
266
				'dataType' => 'html',
267
			), $xhr);
268
			if ($xhr->getLastResponse()->isSuccessful()) {
269
				// if all is ok, repeat this method...
270
				return call_user_func_array(
271
					array('\PhpQuery\Plugin\UtilWebBrowser', 'browserReceive'), array($xhr)
272
				);
273
			}
274
		} else
275
			return $pq;
276
	}
277
        
278
        /**
279
	 * @param Zend_Http_Client $xhr
280
	 */
281
	public static function browserDownload($xhr) {
282
		PhpQuery::debug("[WebBrowser] Received from ".$xhr->getUri(true));
283
		// TODO handle meta redirects
284
		$body = $xhr->getLastResponse()->getBody();
285
286
		return $body;
287
	}
288
289
    /**
290
     * @param      $e
291
     * @param null $callback
292
     */
293
    public static function hadleClick($e, $callback = null) {
294
		$node = PhpQuery::pq($e->target);
295
		$type = null;
0 ignored issues
show
$type is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
296
		if ($node->is('a[href]')) {
297
			// TODO document.location
298
			$xhr = isset($node->document->xhr)
299
				? $node->document->xhr
300
				: null;
301
			$xhr = PhpQuery::ajax(array(
302
				'url' => resolve_url($e->data[0], $node->attr('href')),
303
				'referer' => $node->document->location,
304
			), $xhr);
305 View Code Duplication
			if ((! $callback || !($callback instanceof \Callback)) && $e->data[1])
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
306
				$callback = $e->data[1];
307
			if ($xhr->getLastResponse()->isSuccessful() && $callback)
308
				PhpQuery::callbackRun($callback, array(
309
					self::browserReceive($xhr)
310
				));
311
		} else if ($node->is(':submit') && $node->parents('form')->size())
312
			$node->parents('form')->trigger('submit', array($e));
313
	}
314
315
    /**
316
     * Enter description here...
317
     *
318
     * @TODO trigger submit for form after form's  submit button has a click event
319
     * @param      $e
320
     * @param null $callback
321
     */
322
	public static function handleSubmit($e, $callback = null) {
323
		$node = PhpQuery::pq($e->target);
324
		if (!$node->is('form') || !$node->is('[action]'))
325
			return;
326
		// TODO document.location
327
		$xhr = isset($node->document->xhr)
328
			? $node->document->xhr
329
			: null;
330
		$submit = pq($e->relatedTarget)->is(':submit')
331
			? $e->relatedTarget
332
				// will this work ?
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
333
//			: $node->find(':submit:first')->get(0);
334
			: $node->find('*:submit:first')->get(0);
335
		$data = array();
336
		foreach($node->serializeArray($submit) as $r)
337
		// XXXt.c maybe $node->not(':submit')->add($sumit) would be better ?
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
338
//		foreach($node->serializeArray($submit) as $r)
339
			$data[ $r['name'] ] = $r['value'];
340
		$options = array(
341
			'type' => $node->attr('method')
342
				? $node->attr('method')
343
				: 'GET',
344
			'url' => resolve_url($e->data[0], $node->attr('action')),
345
			'data' => $data,
346
			'referer' => $node->document->location,
347
//			'success' => $e->data[1],
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
348
		);
349
		if ($node->attr('enctype'))
350
			$options['contentType'] = $node->attr('enctype');
351
		$xhr = PhpQuery::ajax($options, $xhr);
352 View Code Duplication
		if ((! $callback || !($callback instanceof Callback)) && $e->data[1])
0 ignored issues
show
The class PhpQuery\Plugin\Callback does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
353
			$callback = $e->data[1];
354
		if ($xhr->getLastResponse()->isSuccessful() && $callback)
355
			PhpQuery::callbackRun($callback, array(
356
				self::browserReceive($xhr)
357
			));
358
	}
359
}
360
/**
361
 *
362
 * @link http://www.php.net/manual/en/function.parse-url.php
363
 * @author stevenlewis at hotmail dot com
364
 */
365
function glue_url($parsed)
366
    {
367
    if (! is_array($parsed)) return false;
368
    $uri = isset($parsed['scheme']) ? $parsed['scheme'].':'.((strtolower($parsed['scheme']) == 'mailto') ? '':'//'): '';
369
    $uri .= isset($parsed['user']) ? $parsed['user'].($parsed['pass']? ':'.$parsed['pass']:'').'@':'';
370
    $uri .= isset($parsed['host']) ? $parsed['host'] : '';
371
    $uri .= isset($parsed['port']) ? ':'.$parsed['port'] : '';
372
    if(isset($parsed['path']))
373
        {
374
        $uri .= (substr($parsed['path'],0,1) == '/')?$parsed['path']:'/'.$parsed['path'];
375
        }
376
    $uri .= isset($parsed['query']) ? '?'.$parsed['query'] : '';
377
    $uri .= isset($parsed['fragment']) ? '#'.$parsed['fragment'] : '';
378
    return $uri;
379
    }
380
/**
381
 * Enter description here...
382
 *
383
 * @author adrian-php at sixfingeredman dot net
384
 */
385
function resolve_url($base, $url) {
386
        if (!strlen($base)) return $url;
387
        // Step 2
388
        if (!strlen($url)) return $base;
389
        // Step 3
390
        if (preg_match('!^[a-z]+:!i', $url)) return $url;
391
        $base = parse_url($base);
392
        if ($url{0} == "#") {
393
                // Step 2 (fragment)
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
394
                $base['fragment'] = substr($url, 1);
395
                return unparse_url($base);
396
        }
397
        unset($base['fragment']);
398
        unset($base['query']);
399
        if (substr($url, 0, 2) == "//") {
400
                // Step 4
401
                return unparse_url(array(
402
                        'scheme'=>$base['scheme'],
403
                        'path'=>substr($url,2),
404
                ));
405
        } else if ($url{0} == "/") {
406
                // Step 5
407
                $base['path'] = $url;
408
        } else {
409
                // Step 6
410
                $path = explode('/', $base['path']);
411
                $url_path = explode('/', $url);
412
                // Step 6a: drop file from base
413
                array_pop($path);
414
                // Step 6b, 6c, 6e: append url while removing "." and ".." from
415
                // the directory portion
416
                $end = array_pop($url_path);
417
                foreach ($url_path as $segment) {
418 View Code Duplication
                        if ($segment == '.') {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
419
                                // skip
420
                        } else if ($segment == '..' && $path && $path[sizeof($path)-1] != '..') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $path of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
421
                                array_pop($path);
422
                        } else {
423
                                $path[] = $segment;
424
                        }
425
                }
426
                // Step 6d, 6f: remove "." and ".." from file portion
427
                if ($end == '.') {
428
                        $path[] = '';
429 View Code Duplication
                } else if ($end == '..' && $path && $path[sizeof($path)-1] != '..') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $path of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
430
                        $path[sizeof($path)-1] = '';
431
                } else {
432
                        $path[] = $end;
433
                }
434
                // Step 6h
435
                $base['path'] = join('/', $path);
436
437
        }
438
        // Step 7
439
        return glue_url($base);
440
}
441
442
function unparse_url($parsed_url) {
443
    $scheme   = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
444
    $host     = isset($parsed_url['host']) ? $parsed_url['host'] : '';
445
    $port     = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
446
    $user     = isset($parsed_url['user']) ? $parsed_url['user'] : '';
447
    $pass     = isset($parsed_url['pass']) ? ':' . $parsed_url['pass']  : '';
448
    $pass     = ($user || $pass) ? "$pass@" : '';
449
    $path     = isset($parsed_url['path']) ? $parsed_url['path'] : '';
450
    $query    = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
451
    $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
452
    return "$scheme$user$pass$host$port$path$query$fragment";
453
}