Skip to content

PHPLIB-1162: Remove unused argument Explainable::getCommandDocument(Server $server) #1102

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 2 commits into from
Jun 12, 2023

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Jun 12, 2023

@GromNaN GromNaN requested review from jmikola and alcaeus June 12, 2023 09:43
@@ -32,5 +32,5 @@ interface Explainable extends Executable
*
* @return array
*/
public function getCommandDocument(Server $server);
Copy link
Member Author

@GromNaN GromNaN Jun 12, 2023

Choose a reason for hiding this comment

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

This interface is @internal, we can change it without breaking user code as no one is expected to implement this interface outside of this library. Even if someone calls this public method with an argument, it will be ignored by PHP.

Copy link
Member

@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

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

Code changes LGTM. I'm a little bit on the fence about whether we should make this change.

FWIW, the $server parameter was added as back then the FindAndModify operation used it in its createCommandDocument method to appropriately add the bypassDocumentValidation option. However, this was removed as part of #893 when we cleaned up pre-3.6 logic. There could be future cases in which the command document might depend on a selected server to add the correct options, in which case we'd be adding the parameter back to every Explainable.

@GromNaN
Copy link
Member Author

GromNaN commented Jun 12, 2023

Interesting. To reduce coupling, it might be replaced by the server info array when the needs to check server version pops again.

@jmikola
Copy link
Member

jmikola commented Jun 12, 2023

Code changes LGTM. I'm a little bit on the fence about whether we should make this change.

@alcaeus: Thanks for saving me the trouble of digging up the historical references.

To reduce coupling, it might be replaced by the server info array when the needs to check server version pops again.

The dominate use case for Server arguments in execute() methods (similar to this) is calling server_supports_feature(), which does only need Server::getInfo(). I don't feel strongly about this, though, since it would just put the onus on each operation to extract the min/max wire versions.

I reckon the only real benefit is we might be able to write unit tests for server_supports_feature() (IIRC mocking the server isn't feasible).

Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

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

I don't object to removing Server from the interface since it's no longer used. If we ever need to add it back I expect we'd dig up this issue/commit via git-blame.

As for server_supports_feature(), my preference is to leave that as-is despite the coupling if that (a) makes the code more readable and (b) reduces extra code needed in calling contexts.

@GromNaN GromNaN merged commit b97cffb into mongodb:master Jun 12, 2023
@GromNaN GromNaN deleted the PHPLIB-1162 branch June 12, 2023 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants