ARACOOOL /
dHttp
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * dHttp is library to work with Curl |
||
| 4 | * Example to use library |
||
| 5 | */ |
||
| 6 | |||
| 7 | include_once('src/Client.php'); |
||
| 8 | include_once('src/Response.php'); |
||
| 9 | |||
| 10 | $http = new dHttp\Client('http://website.com', [ |
||
| 11 | CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 5.1; rv:5.0.1) Gecko/20100101 Firefox/5.0.1', |
||
| 12 | CURLOPT_TIMEOUT => 5, |
||
| 13 | CURLOPT_HEADER => true |
||
| 14 | ]); |
||
| 15 | |||
| 16 | /* |
||
| 17 | * Simple get request |
||
| 18 | */ |
||
| 19 | $resp = $http->get(); |
||
| 20 | // Get response code |
||
| 21 | $resp->getCode(); |
||
|
0 ignored issues
–
show
|
|||
| 22 | // Get response body |
||
| 23 | $resp->getBody(); |
||
|
0 ignored issues
–
show
The call to the method
dHttp\Response::getBody() seems un-needed as the method has no side-effects.
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left. Let’s take a look at an example: class User
{
private $email;
public function getEmail()
{
return $this->email;
}
public function setEmail($email)
{
$this->email = $email;
}
}
If we look at the $user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.
On the hand, if we look at the $user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
// instance variable).
Loading history...
|
|||
| 24 | // Get request errors |
||
| 25 | $resp->getErrors(); |
||
|
0 ignored issues
–
show
The call to the method
dHttp\Response::getErrors() seems un-needed as the method has no side-effects.
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left. Let’s take a look at an example: class User
{
private $email;
public function getEmail()
{
return $this->email;
}
public function setEmail($email)
{
$this->email = $email;
}
}
If we look at the $user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.
On the hand, if we look at the $user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
// instance variable).
Loading history...
|
|||
| 26 | |||
| 27 | /* |
||
| 28 | * Simple post request |
||
| 29 | */ |
||
| 30 | $resp = $http->post([ |
||
| 31 | 'field1' => 'value1', |
||
| 32 | 'field2' => 'value2', |
||
| 33 | ]); |
||
| 34 | |||
| 35 | $resp->getRaw(); |
||
|
0 ignored issues
–
show
The call to the method
dHttp\Response::getRaw() seems un-needed as the method has no side-effects.
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left. Let’s take a look at an example: class User
{
private $email;
public function getEmail()
{
return $this->email;
}
public function setEmail($email)
{
$this->email = $email;
}
}
If we look at the $user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.
On the hand, if we look at the $user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
// instance variable).
Loading history...
|
|||
| 36 | // Return response headers |
||
| 37 | $resp->getHeaders(); |
||
|
0 ignored issues
–
show
The call to the method
dHttp\Response::getHeaders() seems un-needed as the method has no side-effects.
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left. Let’s take a look at an example: class User
{
private $email;
public function getEmail()
{
return $this->email;
}
public function setEmail($email)
{
$this->email = $email;
}
}
If we look at the $user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.
On the hand, if we look at the $user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
// instance variable).
Loading history...
|
|||
| 38 | // Return a specific (text/html; charset=utf-8) |
||
| 39 | $resp->getHeader('Content-Type'); |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Another way of setting. |
||
| 43 | * Output response |
||
| 44 | */ |
||
| 45 | $http = new dHttp\Client(); |
||
| 46 | |||
| 47 | $http->addOptions([CURLOPT_RETURNTRANSFER => false]) |
||
| 48 | ->setUserAgent('Mozilla/5.0 (Windows NT 5.1; rv:5.0.1) Gecko/20100101 Firefox/5.0.1') |
||
| 49 | ->setCookie('/tmp/cookies.txt') |
||
| 50 | ->setUrl('http://website.com') |
||
| 51 | ->get(); |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Use multi curl |
||
| 55 | */ |
||
| 56 | |||
| 57 | $multi = new dHttp\Client(); |
||
| 58 | $response_array = $multi->multi([ |
||
| 59 | new dHttp\Client('http://website1.com'), |
||
| 60 | |||
| 61 | new dHttp\Client('http://website2.com', [ |
||
| 62 | CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 5.1; rv:5.0.1) Gecko/20100101 Firefox/5.0.1', |
||
| 63 | CURLOPT_TIMEOUT => 5, |
||
| 64 | ]) |
||
| 65 | ]); |
||
| 66 | |||
| 67 | foreach ($response_array as $item) { |
||
| 68 | $resp->getCode(); |
||
|
0 ignored issues
–
show
The call to the method
dHttp\Response::getCode() seems un-needed as the method has no side-effects.
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left. Let’s take a look at an example: class User
{
private $email;
public function getEmail()
{
return $this->email;
}
public function setEmail($email)
{
$this->email = $email;
}
}
If we look at the $user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.
On the hand, if we look at the $user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
// instance variable).
Loading history...
|
|||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Get cURL version |
||
| 73 | */ |
||
| 74 | \dHttp\Client::v(); |
||
| 75 |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call: