There are certain things a lot developers do that are not necessarily good.
In this section we will list some of them.
Hard coding means that a developer is using certain values in the code that are actually values that should be made available in the code through some sort of configuration.
For example placing an API key in the class that makes the request to the API.
The consequence of this is that when we need to change the value we need to modify the code. This is not necessary when the API key is saved in a configuration file and retrieved from the configuration in the code.
Magic numbers are numbers you find in the code. For example in the condition in the declaration of a for loop.
Often the same number is used in different parts of the code, so when the number has to be changed, it will have to be changed in multiple places.
It is always possible to replace the number with a constant.
Variable names (just like class and method names) should be expressive. This means their name should be as meaningful as possible.
Examples of wrong variable names:
$temp
$tmp
$x
$value
Where possible methods should be nice and short.
When methods become too long they also become hard to understand and difficult to modify.
When a method is too long, it is always possible to split it up into multiple methods, this also increases re-usability and possibly decreases code duplication.
This is also called repeating yourself. The DRY principle explained further in this document provides some guidelines to follow to prevent code duplication.
For example having an if statement inside a foreach loop that is nested inside 3 levels of other if statements. This increases the cyclomatic complexity of the code and leaves us with code that is very difficult to understand, let alone test.
In most cases this situation can be avoided by refactoring the code.