-
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?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 |
||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,11 +55,7 @@ public function get($object) | |
{ | ||
$hash = spl_object_hash($object); | ||
|
||
if (isset($this->data[$hash])) { | ||
return $this->data[$hash]; | ||
} | ||
|
||
return null; | ||
return $this->data[$hash] ?? null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. This is an |
||
} | ||
|
||
/** | ||
|
@@ -142,11 +138,11 @@ public function offsetGet($object) | |
{ | ||
$hash = spl_object_hash($object); | ||
|
||
if (isset($this->objects[$hash])) { | ||
return $this->data[$hash]; | ||
if (! isset($this->objects[$hash])) { | ||
throw new \UnexpectedValueException('Object not found.'); | ||
} | ||
|
||
throw new \UnexpectedValueException('Object not found.'); | ||
return $this->data[$hash]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. This approach is about It's about change the order of conditions. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Ok. I will not spend time about this change. |
||
} | ||
|
||
/** | ||
|
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.
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.