New answers tagged

0 votes

PHP Parser and converter - SOLID and DRY

Design patterns 1. Use Dependency Injection Use dependency injection instead of creating parsers and converters in the execute method. This makes your code easier ...
Łukasz D. Tulikowski's user avatar
0 votes

TodoList in Symfony 3

1. Use Exceptions for Errors Instead of returning false use, exceptions. When code encounters an error, it can determine how to proceed, such as logging the error or notifying the user. ...
Łukasz D. Tulikowski's user avatar
1 vote

Justify Text on Image GD PHP

This submission is about performance, yet it contains no timing measurements. Your summary complaint seems to be: For N words we have N calls to bbox() and to render text(), which will take a Long ...
J_H's user avatar
  • 22.1k
6 votes

Sanitize URL string for Insertion Upon DB table via Eloquent model

Beware of re-assigning a variable. In the setter method setUrlAttribute() the variable $saneUrl is over-written numerous times: ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
5 votes
Accepted

Sanitize URL string for Insertion Upon DB table via Eloquent model

The biggest problem here is that you are going overboard with precautions. Security is important, but it must be logical. What ...
Your Common Sense's user avatar
5 votes

Sanitize URL string for Insertion Upon DB table via Eloquent model

As some general feedback, I would say that your unit tests are lacking. It looks like you are just checking that your filter function modifies the input in some way? One of the main jobs of tests are ...
Pierre Menard's user avatar
1 vote

PHP implementing Dependency Injection

Let's Start Simple. There are three types of Dependency Injection: Constructor Injection: with PHPUnit for testing purposes, the "best" DI (for unit tests). Setter Injection: helpful for ...
Łukasz D. Tulikowski's user avatar
2 votes

Image upload filter for PHP

Avoid pitfalls using PHP extensions It is good to be aware of the pitfalls like users attempting to upload non-image files. In order to avoid them PHP extensions like fileinfo offers ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
3 votes

Migrating configuration method

use sorted order when the order is arbitrary For both of those source files I recommend you open them in Emacs and use M-x sort-lines to put the global env vars in alphabetic order. Why? There's an ...
J_H's user avatar
  • 22.1k
1 vote
Accepted

Handling large amount of traits and properties in classes

To reduce redundancy and increase maintainability, you can make the following improvements: Group related traits to reduce the number of use statements and organize your code better. If all traits in ...
Łukasz D. Tulikowski's user avatar
2 votes

Manually inserting or updating a row with timestamps, without Eloquent

Main question Is it the right way to do it, or I can improve it to make it more performant? If the query to find the record to update utilized a primary key instead of timestamp condition then the <...
Sᴀᴍ Onᴇᴌᴀ's user avatar
2 votes

methods to import deposits and trades

General review Overall the code looks a bit lengthy. There are two methods - the first of which is 151 lines, and the second of which is 61 lines. It may be wise to break those up into smaller chunks, ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
2 votes

Migrating configuration method

Commentary on the proposal to switch to using a dot env file Switching to using a dot env file is fine, as modern frameworks like Laravel use them, though as was mentioned in comments it is fine to ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
1 vote

PHP WordPress Code - Pricelist Template

I am not familiar with WP development but I would always advise PHP developers to use a template engine like Twig. Quick gains: separate logic from presentation, reduce the size of your files. And you ...
Kate's user avatar
  • 6,400
2 votes

PHP WordPress Code - Pricelist Template

I don't know anything about Wordpress, so below are some generalized suggestions. Prepare the data first Separating business logic from display logic will make this code much cleaner and easier to ...
Your Common Sense's user avatar
2 votes

A simple PHP login form with PDO

Your code is very dense, but very well indented and easy to read. However, there are still some easy improvements you can implement to make your code a whole lot better. Variable names You have the ...
Ismael Miguel's user avatar
5 votes

A simple PHP login form with PDO

As whole, it's a very robust code. Only some inconsistences can be improved. Error reporting I would start from the infamous piece of code, which fallacy is only matched by its enormous popularity: <...
Your Common Sense's user avatar
6 votes

A simple PHP login form with PDO

General review Consider restricting access to init script At first I saw lib/app_init.php and wondered why a login script would need to alter database tables. ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
2 votes
Accepted

Rails session after migrate from PHP (improved)

Regarding the PHP part, you can make it a bit simpler $result = password_verify($password, $hased_password); exit((int)$result);
Your Common Sense's user avatar

Top 50 recent answers are included