Skip to content

Fix wrong data type in codec tutorial #1194

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
Nov 23, 2023

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Nov 20, 2023

As is, the example would cause a type error. Thanks @OskarStark for bringing this to our attention!

@alcaeus alcaeus requested a review from GromNaN November 20, 2023 08:36
@alcaeus alcaeus self-assigned this Nov 20, 2023
@GromNaN
Copy link
Member

GromNaN commented Nov 20, 2023

@alcaeus the phpcs job should run on this PHP file.

@OskarStark
Copy link
Contributor

Should it be renamed then?

- DateTimeCodec
- DateTimeImmutableCodec

@GromNaN
Copy link
Member

GromNaN commented Nov 20, 2023

Should it be renamed then?

- DateTimeCodec
- DateTimeImmutableCodec

Immutability should be the default and DateTime should be prohibed. The codec name seems correct. It could be more permissive and accept any DateTimeInterface, but always output a DateTimeImmutable.

@OskarStark
Copy link
Contributor

Well if I have to deal with external objects which are using DateTime, I would end up having a DateTimeCodec and a DateTimeImmuatableCodec. I agree that immutability is recommended and would always use it, but maybe I am not in charge of this 🤷‍♂️

@GromNaN
Copy link
Member

GromNaN commented Nov 20, 2023

It's a tutorial, I like that it teaches good practices more broadly than the subject covered.

@OskarStark
Copy link
Contributor

I totally agree, but would change the name anyway to DateTimeImmutable, but its not my decision

@alcaeus
Copy link
Member Author

alcaeus commented Nov 23, 2023

the phpcs job should run on this PHP file.

I deferred this on purpose so that I can use PHP 8.1 syntax in the codec tutorial. If we want to run phpcs, I'll have to change it back to PHP 7.4 syntax.

I decided to ignore the naming discussion as this is just supposed to be inspiration for people. I did however add a note about the codec accepting any DateTimeInterface when encoding to BSON but always decoding to DateTimeImmutable.

@alcaeus alcaeus requested a review from GromNaN November 23, 2023 08:09
Copy link
Contributor

@OskarStark OskarStark left a comment

Choose a reason for hiding this comment

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

❤️

@alcaeus alcaeus merged commit 32ffc7b into mongodb:v1.17 Nov 23, 2023
@alcaeus alcaeus deleted the fix-codec-tutorial branch November 23, 2023 10:37
GromNaN pushed a commit to GromNaN/mongo-php-library that referenced this pull request Nov 28, 2023
* v1.17:
  PHPLIB-1315: Fix psalm errors (mongodb#1198)
  Fix wrong data type in codec tutorial (mongodb#1194)
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