- Features that have been added in version 7 should be evident in code submitted.
- Scalar type declarations
- Return type declarations
- Null coalescing operator
- Code will be formated using the PSR-2 standard
- Functions will not be indented more than 3 times and less than 100 lines. The example below would be rejected
function whatsMyAgeAgain(string $name, string $friend): int
{
if($name != 'admin') {
if($friend != 'admin') {
$guess = getAgeGuess($name, $friend);
if($guess > 1) {
if($guess < 100) {
return $guess;
}
}
}
}
}
- Data validation will not be nested
function nameIsValid(string $name): bool
{
if(strlen($name) > 3) {
if(strlen($name) < 20) {
return true;
}
}
return false;
}
Should be refactored into ...
function nameIsValid(string $name): bool
{
if(strlen($name) < 3) {
return false;
}
if(strlen($name) > 20) {
return false;
}
return true;
}
- Functions will be type hinted where ever possible
function assemble(CarInterface $car, EngineInterface $engine, TransmissionInterface $transmission, ColorInterface $color): Car
{
$engine->with($transmission);
$car->engine($engine)->colour($colour);
return $car;
}
- Docblocks on functions and properties, the very minimum a description
- Function and Class names shall be camel case
class SomeClass
{
abstract public function makeSomeThingAwesome(): SomeAwesomeThing;
}
- Input parameters shall be snake case
{
"snake_case_readable_in_data": "This is how it goes"
}
- Exceptions should be used at every posible case
function fetchUserById(int $id): UserInterface
{
if($id < 0) {
throw new InvalidArgumentException('User ID must be a positive integer');
}
$user = $this->repo->find($id);
if(! $user) {
throw new RuntimeException('User not found');
}
return $user;
}
{
"require": {
"php": ">=7"
}
}
- Database changes will always be written in migrations
Date
,Datetime
,Timestamp
will always beDateTime::W3C
format, e.g.2005-08-15T15:52:01+00:00
ordate('Y-m-d\TH:i:sO')
- Booleans shall be integers (
TINYINT
) of1
or0
(not strings of "yes", "no", "maybe", "perhaps" or "sorta") - Character Set will always be
utfmb4
- String, Varchar, Char length will not exceed
191
characters (maximum multibyte string to fit into 256 bytes datatype)
- All projects will contain a
.editorconfig
file
root = true
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
[*.{js,yml}]
indent_size = 2