c-harris /
phpquery
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
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
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
|
|||
| 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
|
|||
| 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
|
|||
| 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
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 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
|
|||
| 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
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 For '' == 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 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 dependenciesPHP Analyzer uses your Are you sure this class is defined by one of your dependencies, or did you maybe
not list a dependency in either the 2. Missing use statementPHP does not complain about undefined classes in 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 These 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
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 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
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 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 | } |