app() helper abuse #5604
krzysztofrewak
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! I noticed that
app()
helper is used a lot in Monica. It's almost 150 occurences inapp/Http
directory and these are simple thing like thisapp/Http/Controllers/SettingsController.php:155
:It could be rewritten into something more readable, custommizable and IDE-friendly:
But I think it's sort of OK to use this on controller layer. More worrying is use of
app()
everywhere in services, like here, inapp/Services/Account/Settings/DestroyAccount.php:65
:Laravel provides a very nice dependency injection management and refactored example below would be a way better approach (especially when
app(DestroyAllPhotos::class)
is used twice in the same class):There's 257 occurences total of
app()
in entireapp
directory. It's a lot, but it could be easily refactored into something more maintanable and modern. Separating service layer from Laravel-specific helpers would be fine too.I could help with that, but I would like to confirm if that would be okay with you. I don't want to do any useless work and receive PR comment that this is against some of your internal rules or style of development. ;)
Btw. I'm also little worried about
auth()->user()
usage. There can be like 9 occurences across 15 lines in some controllers. I could help with refactoring these too. Then this:could be little faster:
Beta Was this translation helpful? Give feedback.
All reactions