Skip to content

Commit b84224e

Browse files
author
Martin Brecht-Precht
committed
Fixed some minor code style and performance issues.
1 parent a8574eb commit b84224e

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

.codeclimate.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ ratings:
2727
- "**.rb"
2828
exclude_paths:
2929
- test/
30-
- vendor/
30+
- vendor/

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,4 +419,4 @@ Contributing to our projects is always very appreciated.
419419

420420
## License
421421

422-
PHP Basic HTTP Client is under the MIT license.
422+
PHP Basic HTTP Client is under the MIT license.

phpunit.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
</exclude>
1515
</whitelist>
1616
</filter>
17-
</phpunit>
17+
</phpunit>

src/Request/AbstractRequest.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,11 @@ public function addAuthentication(AuthenticationInterface $authentication)
212212
*/
213213
public function removeAuthentication(AuthenticationInterface $authentication)
214214
{
215-
for ($i = 0; $i < count($this->authentications); $i++) {
215+
$authenticationCount = count($this->authentications);
216+
for ($i = 0; $i < $authenticationCount; $i++) {
216217
if ($this->authentications[$i] == $authentication) {
217218
unset($this->authentications[$i]);
219+
$this->authentications = array_values($this->authentications);
218220
return $this;
219221
}
220222
}
@@ -295,7 +297,8 @@ public function perform()
295297
$this->configureCurl($curl);
296298
$this->getTransport()->configureCurl($curl);
297299
$this->getMessage()->configureCurl($curl);
298-
for ($i = 0; $i < count($this->authentications); $i++) {
300+
$authenticationCount = count($this->authentications);
301+
for ($i = 0; $i < $authenticationCount; $i++) {
299302
$this->authentications[$i]
300303
->validate($this)
301304
->configureCurl($curl);

src/Request/Message/Message.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,11 @@ public function removeCookieByName($name)
251251
$argumentType = (is_object($name)) ? get_class($name) : gettype($name);
252252
throw new \InvalidArgumentException('Expected the name as string. Got ' . $argumentType);
253253
}
254-
for ($i = 0; $i < count($this->cookies); $i++) {
254+
$cookieCount = count($this->cookies);
255+
for ($i = 0; $i < $cookieCount; $i++) {
255256
if ($this->cookies[$i]->getName() !== $name) {
256257
unset($this->cookies[$i]);
258+
$this->cookies = array_values($this->cookies);
257259
return $this;
258260
}
259261
}
@@ -266,9 +268,11 @@ public function removeCookieByName($name)
266268
*/
267269
public function removeCookie(CookieInterface $cookie)
268270
{
269-
for ($i = 0; $i < count($this->cookies); $i++) {
271+
$cookieCount = count($this->cookies);
272+
for ($i = 0; $i < $cookieCount; $i++) {
270273
if ($cookie == $this->cookies[$i]) {
271274
unset($this->cookies[$i]);
275+
$this->cookies = array_values($this->cookies);
272276
return $this;
273277
}
274278
}
@@ -415,7 +419,8 @@ private function findHeadersByName($name)
415419
*/
416420
private function findHeaderIndex(HeaderInterface $header)
417421
{
418-
for ($i = 0; $i < count($this->headers); $i++) {
422+
$headerCount = count($this->headers);
423+
for ($i = 0; $i < $headerCount; $i++) {
419424
if ($this->headers[$i] === $header) {
420425
return $i;
421426
}

0 commit comments

Comments
 (0)