Skip to content
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

PHPLIB-1185: Add new methods to get database and collection instances #1494

Merged
merged 2 commits into from
Nov 4, 2024

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Oct 23, 2024

PHPLIB-1185

This PR adds the following new methods:

  • Client::getDatabase, changed Client::selectDatabase and Client::__get to proxy to this method
  • Client::getCollection, changed Client::selectCollection to proxy to this method
  • Database::getCollection, changed Database::selectCollection and Database::__get to proxy to this method

Since they are widely used, I did not add any deprecation warnings, nor did I add any language to the documentation to indicate that they are deprecated. I left the tests as they are, as the old methods were changed to proxy to the new methods, so we are implicitly testing them. I can duplicate the existing tests, but I don't think this is necessary.

As a follow-up to this PR, we should update the documentation to use the new get(Database|Collection) methods, starting in 2.0 (as we only maintain a single documentation for 1.x, so users would have to figure out which method is correct for their version).

@alcaeus alcaeus requested a review from jmikola October 23, 2024 09:01
@alcaeus alcaeus requested a review from a team as a code owner October 23, 2024 09:01
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

LGTM

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.

A few suggestions to doc blocks.

* @param string $databaseName Name of the database containing the collection
* @param string $collectionName Name of the collection to select
* @param array $options Collection constructor options
* @throws InvalidArgumentException for parameter/option parsing errors
Copy link
Member

Choose a reason for hiding this comment

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

I suppose you want the doc block for the note about "does not exist", but the parameter annotations here have no value. The code is self-documenting.

Copy link
Member

Choose a reason for hiding this comment

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

Does it helps static analysis to tell which kind of exception can be thrown?

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps, but since there is no throws within this method I would assume that tooling would inherit from doc blocks of any referenced methods, which would have @throws. I'll defer to you guys, though.

Copy link
Member Author

@alcaeus alcaeus Nov 4, 2024

Choose a reason for hiding this comment

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

I left @throws in for the time being, since they are included in all other methods as well. I'm on the fence about the usefulness of them, I can see them being useful when coupled with static analysis, but since we don't have anything to enforce correctness of @throws statements, we may reconsider having them for methods that don't directly throw any exceptions.

That said, I did remove the @param tags as the parameter names are self-explanatory.

src/Client.php Outdated Show resolved Hide resolved
src/Database.php Outdated Show resolved Hide resolved
@alcaeus alcaeus force-pushed the phplib-1185-get-database-collection branch from e33b967 to ef20376 Compare November 4, 2024 12:29
@alcaeus alcaeus enabled auto-merge (squash) November 4, 2024 12:31
@alcaeus alcaeus merged commit 4c7b1cb into mongodb:v1.x Nov 4, 2024
31 checks passed
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