deployer
deployer copied to clipboard
[httpie] Delete unnecessary clone
-
[ ] Bug fix #…?
-
[ ] New feature?
-
[ ] BC breaks?
-
[ ] Tests added?
-
[ ] Docs added?
Please, regenerate docs by running next command: $ php bin/docgen
This is a big breaking change. Why?
This change don't break anything. All works the same.
It is NOT necessary to clone this object. We change directly the attributes in the received instance.
When I have time I'll add tests to this class. And it will be easier to make changes.
Clone is essential part. One can create a "boilerplate" and copy it via the method. Probably somebody relays on it already.
But this is the contrary. Clone it when you need it. And not httpie.
return Httpie::get($url)->header(....)->send()
Here we don't need it.
$response1 = Httpie::get($url)->header(....);
Here is the same if it's cloned or not;
$result = $response1->jsonBody(...)->send();
$result2 = $response1->formBody(...)->send();
Also here we don't need it cloned.
$response2 = $response1->jsonBody(...);
Here response2 is a copy of $reponse1, but like you said we changed $reponse1 too.
And the logical is that the developer use the clone if they want it. Not automatically Httpie.
$response2 = clone $response1;
$response2->jsonBody(....);
It's more logical to the developer clone it.
$response2 = $response1->jsonBody(...);
This look like you changed $response1 too.
But you are who will decide every PR we send you.
Also it's possible to add a clone() method. And that will be semantically correct. But unnecessary too.
A good example is the fetch() function
It's working without clone, but we can simplify the code, and use less instances.
Now:
$http = $http->nothrow($nothrow);
foreach ($headers as $key => $value) {
$http = $http->header($key, $value);
}
if ($body !== null) {
$http = $http->body($body);
}
return $http->send($info);
After:
$http->nothrow($nothrow);
foreach ($headers as $key => $value) {
$http->header($key, $value);
}
if ($body !== null) {
$http->body($body);
}
return $http->send($info);
Only 1 instance used.
And we can clone at any moment, if we need it.
$http2 = clone $http;
// or
$http2 = clone $http->body($body);