-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance conditions #3
base: master
Are you sure you want to change the base?
Conversation
$this->handle = (is_resource($file) ? $file : @ fopen($file, 'rb')); | ||
|
||
if ($this->handle === false) { | ||
throw new \InvalidArgumentException('Cannot open file for reading: ' . $file); |
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 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.
What do you mean about this comment?
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 don't like the null coalesce operator here, as it also allows for undefined variable without notice. This operator is equivalent to isset($values) ? $values : [], not strictly equivalent to the original code.
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 condition is not related to the null coalesce operator.
I think this change is proper approach.
src/ObjectArrayStorage.php
Outdated
@@ -49,7 +49,7 @@ public function get($object) : array | |||
{ | |||
$values = $this->storage->get($object); | |||
|
|||
return ($values === null) ? [] : $values; | |||
return $values ?? []; |
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 don't like the null coalesce operator here, as it also allows for undefined variable without notice. This operator is equivalent to isset($values) ? $values : []
, not strictly equivalent to the original code.
} | ||
|
||
throw new \UnexpectedValueException('Object not found.'); | ||
return $this->data[$hash]; |
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 change brings no value.
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 approach is about error exception first
.
It's about change the order of conditions.
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 got that, but what's the point? Please don't spent time on nitpick like this :)
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.
Ok. I will not spend time about this change.
src/ObjectStorage.php
Outdated
} | ||
|
||
return null; | ||
return $this->data[$hash] ?? 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.
You can keep this change alone.
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 about reverting this due to your previous comment.
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 is an isset($x) ? $x : null
, so conceptually equivalent to $x ?? null
. I can accept this change.
Changed log
?:
operator to do that.??
syntax to reduce conditions.Exception
first to enhance condition logic.