-
Notifications
You must be signed in to change notification settings - Fork 152
Conversation
@@ -172,10 +172,10 @@ public function getMetadata($key = null) | |||
return $metadata; | |||
} | |||
|
|||
if (! array_key_exists($key, $metadata)) { | |||
return null; | |||
if (isset($metadata[$key])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return $metadata[$key] ?? null;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea but after drop php5 ;(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wha?! This is for an improvement: just drop it already
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But is it not better to merge it as it to current php5 supported line and then, drop php5 and apply you have suggested?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can optimize for PHP 5.6 today, we can make it even better for the next major release later. I'm fine with this for now.
@@ -107,7 +107,7 @@ public function isSeekable() | |||
*/ | |||
public function seek($offset, $whence = SEEK_SET) | |||
{ | |||
if ($whence == SEEK_SET) { | |||
if ($whence === SEEK_SET) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the FQN for this constant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what are you meant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\SEEK_SET
@@ -60,7 +60,7 @@ public static function fromGlobals( | |||
$files = static::normalizeFiles($files ?: $_FILES); | |||
$headers = static::marshalHeaders($server); | |||
|
|||
if (null === $cookies && array_key_exists('cookie', $headers)) { | |||
if (null === $cookies && isset($headers['cookie'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to introduce tests around null
values to avoid regressions here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's imposible to write this test becase $headers
comes from private function which alware return strings pair array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need then: nullability was just an assumption on my end.
@@ -206,7 +206,7 @@ public static function marshalHeaders(array $server) | |||
|
|||
// We will not overwrite existing variables with the | |||
// prefixed versions, though | |||
if (array_key_exists($key, $server)) { | |||
if (isset($server[$key])) { | |||
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to introduce tests around null
values to avoid regressions here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, particularly as the values may resolve to a false
(e.g., 0
, ''
). The reason array_key_exists()
was used was to allow any value, regardless of whether or not it evaluated as truthy.
@@ -285,11 +285,11 @@ public function getMetadata($key = null) | |||
} | |||
|
|||
$metadata = stream_get_meta_data($this->resource); | |||
if (! array_key_exists($key, $metadata)) { | |||
return null; | |||
if (isset($metadata[$key])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ??
here too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you target PHP 7.1+, you'll need to update the composer.json
, rebase against develop, and change the branch this is against.
@@ -641,7 +641,7 @@ private function filterQuery($query) | |||
private function splitQueryValue($value) | |||
{ | |||
$data = explode('=', $value, 2); | |||
if (1 === count($data)) { | |||
if (! isset($data[1])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is not equivalent to the previous: you need to verify that the key 0
exists too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ocramius explode()
should always has key 0 ? https://3v4l.org/viNZT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ocramius agree with @samsonasik
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, misread
@Ocramius all remarks applied in code or I miss something? |
@snapshotpl tests are failing. Why? |
src/RelativeStream.php
Outdated
{ | ||
if ($whence == SEEK_SET) { | ||
if ($whence === \SEEK_SET) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would go with import the constant as we do in other places for internal functions:
use const SEEK_SET;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with the majority of changes, but I do question whether some of these micro-optimizations make sense, as they make the code less readable.
@@ -206,7 +206,7 @@ public static function marshalHeaders(array $server) | |||
|
|||
// We will not overwrite existing variables with the | |||
// prefixed versions, though | |||
if (array_key_exists($key, $server)) { | |||
if (isset($server[$key])) { | |||
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, particularly as the values may resolve to a false
(e.g., 0
, ''
). The reason array_key_exists()
was used was to allow any value, regardless of whether or not it evaluated as truthy.
|| strpos($mode, 'w') !== false | ||
|| strpos($mode, 'c') !== false | ||
|| strpos($mode, 'a') !== false | ||
|| strpos($mode, '+') !== false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this change "better" or an "optimization", exactly? I find it less readable.
@@ -234,7 +236,7 @@ public function isReadable() | |||
$meta = stream_get_meta_data($this->resource); | |||
$mode = $meta['mode']; | |||
|
|||
return (strstr($mode, 'r') || strstr($mode, '+')); | |||
return (strpos($mode, 'r') !== false || strpos($mode, '+') !== false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above regarding strstr
vs strpos
. I recognize that strpos
is marginally faster, but most folks agree it's a micro-optimization at best. If using it sacrifices readability, I'm not sure the change is useful.
@@ -285,11 +285,11 @@ public function getMetadata($key = null) | |||
} | |||
|
|||
$metadata = stream_get_meta_data($this->resource); | |||
if (! array_key_exists($key, $metadata)) { | |||
return null; | |||
if (isset($metadata[$key])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you target PHP 7.1+, you'll need to update the composer.json
, rebase against develop, and change the branch this is against.
Closing; many changes were requested, but none provided by the author. If you or anyone else reading want to see these changes, please submit a new PR incorporating them, along with the requested feedback. Thanks! |
No description provided.