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

Fix getKeys method #323

Merged
merged 1 commit into from
May 5, 2022
Merged

Fix getKeys method #323

merged 1 commit into from
May 5, 2022

Conversation

alallema
Copy link
Contributor

@alallema alallema commented May 2, 2022

The Client::getKeys method returns the correct number of keys but the same object for all of them.
This was due to the newInstance method which returned the instance instead of a new Instance as its name indicated.

@alallema alallema added the bug Something isn't working label May 2, 2022
@alallema alallema linked an issue May 2, 2022 that may be closed by this pull request
@alallema alallema changed the title Fix method return self instead of new Instance of class Fix getKeys method May 2, 2022
@alallema alallema requested a review from bidoubiwa May 2, 2022 10:44
Comment on lines +38 to +53
$key = new self(
$this->http,
$attributes['key'],
$attributes['description'],
$attributes['actions'],
$attributes['indexes'],
);
if ($attributes['expiresAt']) {
$key->expiresAt = date_create_from_format('Y-m-d\TH:i:s\Z', $attributes['expiresAt']);
}
if ($attributes['createdAt']) {
$key->createdAt = date_create_from_format('Y-m-d\TH:i:s.vu\Z', $attributes['createdAt']);
}
if ($attributes['updatedAt']) {
$key->updatedAt = date_create_from_format('Y-m-d\TH:i:s.vu\Z', $attributes['updatedAt']);
}
Copy link
Contributor

@bidoubiwa bidoubiwa May 2, 2022

Choose a reason for hiding this comment

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

Since every parameter in __construct is optional, should expiresAt, createdAt and updatedAt not be passed to the constructor as well?

In this case we should maybe pass an option object instead of individual parameters

Should we move the if's in the __construct ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we can but it's not the behavior we want I think. The goal of not putting it in the __construct is that you can directly give it a DateTime instead of a string.
And this is a good question because we also can remove this if forest and put it in the function all() instead. But I think this newInstance method is more useful to translate a json document to a Key object.
What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

but we never use new Keys() we always use newInstance. Could you show me a use case where we lose in ease of use?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, we never use new Key() in the class because this is not its purpose. But if you are a user and you want to create a Key you do like:

        Key key = new Key();
        key.setIndexes(new String[] {"*"});
        key.setActions(new String[] {"*"});
        key.setExpiresAt(null);

        client.createKey(key);

You can see more examples in the code-sample.yml file.
And for the newInstance examples I don't, I only used it here. But if you talk about fill() function (the old newInstance() function that I renamed) I used it a lot to fill the Key with a json response from Meilisearch.
Not sure is more clear?

Copy link
Contributor

Choose a reason for hiding this comment

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

    public function create(array $options = []): self

See here

Is this expecting an instance of Keys or an option object?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The both can work but the field expiredAt should be DateTime in all case.

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand my mistake! LGTM !

Copy link
Collaborator

@norkunas norkunas May 5, 2022

Choose a reason for hiding this comment

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

Shouldn't DateTimeImmutable::createFromFormat() be used instead of date_create_from_format ? I mean it should be changed in property declaration and here, because what's the point to have a mutable VO?

@alallema alallema requested review from brunoocasali and bidoubiwa and removed request for brunoocasali May 2, 2022 12:46
Copy link
Contributor

@bidoubiwa bidoubiwa left a comment

Choose a reason for hiding this comment

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

LGTM 🔥

Comment on lines +38 to +53
$key = new self(
$this->http,
$attributes['key'],
$attributes['description'],
$attributes['actions'],
$attributes['indexes'],
);
if ($attributes['expiresAt']) {
$key->expiresAt = date_create_from_format('Y-m-d\TH:i:s\Z', $attributes['expiresAt']);
}
if ($attributes['createdAt']) {
$key->createdAt = date_create_from_format('Y-m-d\TH:i:s.vu\Z', $attributes['createdAt']);
}
if ($attributes['updatedAt']) {
$key->updatedAt = date_create_from_format('Y-m-d\TH:i:s.vu\Z', $attributes['updatedAt']);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand my mistake! LGTM !

@alallema
Copy link
Contributor Author

alallema commented May 5, 2022

bors merge

@bors
Copy link
Contributor

bors bot commented May 5, 2022

@bors bors bot merged commit c28fc1b into main May 5, 2022
@bors bors bot deleted the patch-issue-322 branch May 5, 2022 11:20
bors bot added a commit that referenced this pull request May 9, 2022
324: Update version for the next release (v0.23.2) r=curquiza a=alallema

This version makes this package compatible with MeiliSearch v0.27.0🎉 
Check out the changelog of [MeiliSearch v0.27.0](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.27.0) for more information about the changes.

## 🚀 Enhancements

- Add new methods for the new typo tolerance settings #316 `@alallema`
`index.getTypoTolerance()`
`index.updateTypoTolerance(params)`
`index.resetTypoTolerance()`
- Ensure nested field support #317 `@alallema`
- Add new search parameters highlightPreTag, highlightPostTag and cropMarker #318 `@alallema`

## 🐛 Bug Fixes

* Fix `getKeys` method (#323) `@alallema`

Co-authored-by: alallema <amelie@meilisearch.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

getKeys returns the same Keys object for all keys
3 participants