Skip to content

[SecurityHttp] Implementing Null Object Design Pattern in AuthenticatorManager #45953

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

Closed
wants to merge 2 commits into from

Conversation

Trismegiste
Copy link

Implementing Null Object Design Pattern for $logger and removing 15 (fifteen) ifs.

Slower (in theory) but cleaner.

Q A
Branch? 5.4
Bug fix? no
New feature? no
Deprecations? no
Tickets
License MIT
Doc PR

This is PR is not about bug fix or feature, only about cleaner code (in my humble opinion, less code = less bug).

If you think the CPU cost is first priority (though I think it's negligible), I'll understand you dismiss this PR.

About the tests :

php ./phpunit src/Symfony/Component/Security/Http/
#!/usr/bin/env php
PHPUnit 9.5.20 #StandWithUkraine

Warning:       Your XML configuration validates against a deprecated schema.
Suggestion:    Migrate your XML configuration using "--migrate-configuration"!

Testing /home/flo/Develop/symfony/src/Symfony/Component/Security/Http
...............................................................  63 / 474 ( 13%)
............................................................... 126 / 474 ( 26%)
............................................................... 189 / 474 ( 39%)
............................................................... 252 / 474 ( 53%)
............................................................... 315 / 474 ( 66%)
............................................................... 378 / 474 ( 79%)
............................................................... 441 / 474 ( 93%)
.................................                               474 / 474 (100%)

Time: 00:00.488, Memory: 22.00 MB

OK (474 tests, 981 assertions)

Legacy deprecation notices (103)

Have a nice day.

Florent

…fifteen) ifs.

Slower (in theory) but beautiful.
@carsonbot carsonbot added this to the 5.4 milestone Apr 6, 2022
@wouterj
Copy link
Member

wouterj commented Apr 6, 2022

Hi @Trismegiste!
I see this is your first PR and I must say it looks very complete! Thanks for putting in the time to start contributing 💚 .

Unfortunately, we've rejected changes like this in the past: #14682 There are, imho, two reasons for this:

  1. Performance in this class is critical (it is called at the front of every request within the firewall, most often every request in the application). We sometimes have to give up clean code for performance matters in these critical places.
  2. Symfony is very conservative with changes. In the past, we've learned that minor changes that didn't seem to have any impact can lead to broken applications after an upgrade. The last thing we want is breaking production apps after upgrading from 5.4.x to 5.4.(x+1).
    This means that everything that is not 100% clear a bug fix is often considered a feature (and thus included in the unstable branch, 6.1 at the moment). However, with changes like this, the value of the change is not existent (for the end user). In those cases, it's often better to not do the change at all.

So my vote would be 👎 here, unfortunately.

If you want to contribute to Symfony, but aren't sure what to do, feel welcome to join the #contribs channel on Symfony slack. Maybe we can find a nice issue or feature for you to work on :)

@ro0NL
Copy link
Contributor

ro0NL commented Apr 6, 2022

PHP 8 allows a null safe operator ;)

alernatively we do $this->logger && $this->logger->... here and there i believe

@Trismegiste
Copy link
Author

Hello @wouterj , thank you for your fast reply

Performance in this class is critical (it is called at the front of every request within
the firewall most often every request in the application). We sometimes have to give up
clean code for performance matters in these critical places.

I completely understand 👍

This means that everything that is not 100% clear a bug fix is often considered a feature (and thus included
in the unstable branch, 6.1 at the moment). However, with changes like this, the value of the change is not
existent (for the end user). In those cases, it's often better to not do the change at all.

I also agree with the « if it ain't broke, don't fix it » 😉

Anyway, thank you for your explanations, that's very kind ❤️

@nicolas-grekas
Copy link
Member

Closing as explained, can't wait your next PR @Trismegiste :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants