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

return self on builder methods for more consistent behaviour #1609

Merged
merged 1 commit into from
Mar 7, 2022

Conversation

codemasher
Copy link
Contributor

Just an example i just ran into:

$formatter = (new LineFormatter)
    ->setJsonPrettyPrint(true) // -> LineFormatter instance
    ->addJsonEncodeOption(JSON_UNESCAPED_SLASHES) // -> void
    ->addJsonEncodeOption(JSON_UNESCAPED_UNICODE); // boo!

I didn't go through the handler classes to check for similar cases.

@juan-morales
Copy link
Contributor

In my own opinion, applying this pattern is nice, and gives us the possibility to write more readable code. Despite that, I believe that you should apply this pattern everywhere, at least all default formatters, to have a uniform code structure.

For example:

File: src/Monolog/Formatter/LineFormatter.php , is not on this change, and imo it should.

Can you please check a bit more in the code in order to apply uniformly this pattern wherever it needs to b applied? I also like this approach/pattern/style by the way.

Copy link
Contributor

@juan-morales juan-morales left a comment

Choose a reason for hiding this comment

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

imo, there is/are missing place/s as I pointed in my comment.

@codemasher
Copy link
Contributor Author

codemasher commented Nov 18, 2021

You're right, I've overlooked this (and probably more). Also, i was hesitant to change Logger::reset() (ResettableInterface) and maybe even Logger::close(). I'll recheck when i got more time, also feel free to point out what I may have missed. :)

(Personally i despise public setter and builder methods that return void for no apparent reason and while this may be opinionated (like almost everything in programming), maybe just let people have nice things?)

@Seldaek Seldaek added this to the 2.x milestone Mar 7, 2022
@Seldaek Seldaek added the Feature label Mar 7, 2022
@Seldaek Seldaek merged commit 168bb6e into Seldaek:main Mar 7, 2022
@Seldaek
Copy link
Owner

Seldaek commented Mar 7, 2022

Thanks

@lyrixx lyrixx mentioned this pull request Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants