Skip to content

Return points, spelling and dead code #304

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

Merged
merged 5 commits into from
Oct 3, 2016

Conversation

calcinai
Copy link
Contributor

Replaces #302

@calcinai calcinai mentioned this pull request Aug 23, 2016
@bighappyface
Copy link
Collaborator

@calcinai please check the PR build for test failures

@calcinai
Copy link
Contributor Author

Oh no! Do you think the tests should actually be updated in this case? From my understanding that function is designed to throw an exception or silently return?

@calcinai
Copy link
Contributor Author

calcinai commented Aug 23, 2016

Have updated the test, I can only assume that this is desired behaviour - it would be an incredibly strange case if someone was actually looking for nulls in this case..

@bighappyface
Copy link
Collaborator

@calcinai thanks for this work.

While the updating some return values to match doc blocks makes a lot of sense, I want to caution that there are some BC implications to changing return values. My assessment is that no external uses would change so I think we are good, but I would like a second opinion.

@FlorianSW @mirfilip @thewilkybarkid @narcoticfresh do you see any BC issues with this? Rolling 4.0.0 is not desireable to me at the present time.

*/
public function confirmMediaType($uriRetriever, $uri)
{
$contentType = $uriRetriever->getContentType();

if (is_null($contentType)) {
// Well, we didn't get an invalid one
return;
return true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, how many users uses this method, but changing from null to a boolean value could be problematic, especially in code something like:

if ( confirmMediaType( $uriRetriever, $uri ) ) {
  // the code that runs when true
} else {
  // the former "null" value-code
}

It now would break, as null evaluates to false, and not to true. So in some cases, this could be a problem. However, the new values makes sense, too. I'm really not sure :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that (in master) the function could return true when it's a schema from json-schema.org, and null if it is explicitly valid, it just isn't seem all that logical. The only usage internally just relies on it halting with an exception if it's invalid.

Is it even feasible that someone has written code to handle the different return types? If you're using the library for validation, it's going to be called again anyway and you won't have any control of the result..

That said, maybe there is an argument for leaving it as it is, because the return value is basically irrelevant anyway!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FlorianSW thank you so much for your feedback. This is exactly my concern.

As you pointed out, null is falsy. Perhaps returning false here is the solution as it would be compliant with the bool return type and also be compatible with previous control-flow usage, although that would not be true for === null or is_null comparisons.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving forward with this, should I just revert the section in question?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintaining BC is preferred.

@bighappyface
Copy link
Collaborator

+1

@bighappyface bighappyface merged commit 26605ef into jsonrainbow:master Oct 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants