...
if
,elseif
,while
,for
: need a space between theif
keyword and the parentheses()
.Code Block borderStyle solid if (<condition>) while (<condition>)
When a combination of
if
andelse
is used and both can return a value, theelse
statement has to be omitted.Code Block borderStyle solid if (<condition>) return false; return true;
Note title Recommendation We recommend you to use only one
return
statement per method/function.When a method/function returns a boolean and the current method/function's returned value depends on it, the
if
statement has to be avoided.Code Block borderStyle solid public aFirstMethod() { return $this->aSecondMethod(); }
Tests must be grouped by entity.
Code Block borderStyle solid if ($price AND&& !empty($price)) ... if (!Validate::$myObject OR|| $myObject->id === NULL) ...
...
- It is forbidden to use a ternary into another ternary, such as
echo ((true ? 'true' : false) ? 't' : 'f');
. - We recommend the use of
&&
and||
into your conditions instead ofAND
andOR
:echo ('X' == 0 && 'X' == true)
. Please refrain from using reference parameters, such as:
Code Block function is_ref_to(&$a, &$b) { ... }
...