Code Review: PHP Static Helper with HTTP Request

preview_player
Показать описание
Reviewing Laravel code from an open-source project, my "reaction" to it.

Related links:

- - - - -
Support the channel by checking out my products:

- - - - -
Other places to follow:
Рекомендации по теме
Комментарии
Автор

I don't necessarily think that a specific exception would need to be thrown if the page's title couldn't be found/fetched. I would probably return *null* though instead of an empty string just to be more clear. It might also be good to check that the title isn't actually just an empty string (and if so, return *null* as well).

JJASMR
Автор

2:38 html_entity_decode() is the opposite of htmlentities() in that it converts HTML entities in the string to their corresponding characters.

plango
Автор

I need your opinion on this. Combining show and index with an optional ID.

MuhammadTalha-kov
Автор

What bugs me most in these helper methods is that there is always some magic number deep down in there. In this particular code there's no way for any developer to change the timeout value. Why exactly 30? Why not 5? Also testing becomes unecessary harder. I would make the timeout an optional argument with a sane default value.

jdrab
Автор

Overall a good video, but having a quick look through the repo, they're using Svelte for the frontend. I'm not expecting a channel about PHP and Laravel to be an expert on a 2nd-class citizen framework to Laravel (i.e.: compared to Vue/React), but I wouldn't write off so quickly that the project doesn't handle the UX like was mentioned.

I can't say for sure the author did, but this video only walked through the PHP logic and nothing regarding the frontend even though the frontend was a constructive criticism element.

erichansen
Автор

slightly related, I needed to convert number of seconds. Found a way to it with the Carbon. Was about 5 lines of code. Kept looking and found "gmdate("H:i:s", $duration)"

tmspm
Автор

Dear sir,
i have question about eloquent data retrieve. I have two tables categories and menus, between those two have many to many relationship. But category_menu table haven't timestamp. I want retrieve one latest menus from each category. So can you explain how to do that?

chameeradinesh
Автор

Since static methods belong to the class and not a particular instance, mocking them becomes difficult and dangerous

andrews
Автор

How you feel about not using {} when there is only one line of code in a block?

if (condition) expression;

instead of

if (condition) {
expression;
}

My, absolutely negative. It's very easy to make mistakes when changes code. And you also have to spend more time on code review because it is not standard formatting. Plus, there are currently languages where formatting creates blocks of code. And that kind of experience again slows down the reading of the code.

Maybe a little voting. Like if you agree. Dislike if you regularly use such one-line expressions without block quotes.

Andris_Briedis
Автор

Actually, I'm not a big fan of helper, I think it is anti design pattern that should be avoided.🙂

ferasmasoud