-
Notifications
You must be signed in to change notification settings - Fork 135
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
Config::has should check for key presence #66
Config::has should check for key presence #66
Conversation
* release/0.9.1: Updated Travis CI configuration
…ming that a null value equals the configuration doesn't have the requested key.
rearrange error handling to reach 100% test coverage;
PSR2 corrections as generated by PHPCBF;
Provide package-level exceptions
+1 -- I'm inclined to agree with the rationale here, that the expectation of the contract from I concede that the docblock currently states "checking if configuration values exist", but I'd argue that Rule of Least Surprise backs up that the most common expectation from reading |
@@ -129,7 +129,25 @@ public function set($key, $value) | |||
*/ | |||
public function has($key) | |||
{ | |||
return !is_null($this->get($key)); | |||
// Check if already cached |
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.
Since this is effectively copying the current body of get()
, I'd suggest letting has()
prime the cache when the key is found. You can then remove all this similar logic from get()
, and just have get()
call out to has()
to see if it exists. If has()
says false, then get()
returns $default
... if it says TRUE, then get()
can return it right out of the cache.
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. I've also changed a little "side effect" the get method had, namely that it would set in cache the default value if the key didn't exist, which I think should not happen.
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.
Ah, good catch... I agree that would be unexpected behavior to me.
8850422
to
236d0a2
Compare
…ming that a null value equals the configuration doesn't have the requested key.
…t-extension Add support for .dist extensions files
…ming that a null value equals the configuration doesn't have the requested key.
236d0a2
to
2b9967c
Compare
Replaced by PR #72 targeting |
* release/0.10.0: Updated `CHANGELOG.md` [#66] Check if the configuration key exists instead of assuming that a null value equals the configuration doesn't have the requested key. Add support for .dist extensions files rearrange error handling to reach 100% test coverage; PSR2 corrections as generated by PHPCBF; provide package-level exceptions, so that callers can catch at the package level;
The current code in
AbstractConfig::has
is not going to return an expected result if the value in the configuration isnull
.In this particular case,
AbstractConfig::has
will returnfalse
even if ithas
the keysomekey
.