# Coding Standard
The coding standard exists as good practice for keeping the syntax cohesive as possible. We have created our own coding standard which can be automatic implemented in your project.
# Casing
PascalCase
for classes and interfacesSCREAMING_SNAKE_CASE
for constantssnake_case
for HTTP parameters, database columnscamelCase
for everything else
# Code style
Code style is provided using EasyCodingStandard (opens new window), defined at the root ecs.php
file which extends ecs-chevere.php (opens new window).
# Implementing in your project
Install EasyCodingStandard with composer.
composer require symplify/easy-coding-standard --dev
# Download code-style
Run this to download/update the base code style.
mkdir -p .ecs \
&& cd .ecs \
&& curl -O https://raw.githubusercontent.com/chevere/code-style/main/.ecs/ecs-chevere.php
💡 For Chevere packages you can run composer update-cs
# .ecs/ecs.php
Create your .ecs/ecs.php
configuration (opens new window) file by importing the ecs-chevere.php
file:
<?php
declare(strict_types=1);
use Symplify\EasyCodingStandard\Config\ECSConfig;
return static function (ECSConfig $ecsConfig): void {
$ecsConfig->import(__DIR__ . '/ecs-chevere.php');
$ecsConfig->skip([
__DIR__ . '/vendor/*',
]);
};
# Custom header comment
Use a plain text file at .ecs/.header
to define the header comment for your coding standard.
This file is part of projectName.
(c) My Name <user@email-hostname>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
# Format code style
To format code style you need to run:
vendor/bin/ecs --config='.ecs/ecs.php' check file.php --fix
Check the workspace documentation to configure automatic code formatting.
# Composer commands
Add the following scripts to your composer.json
file:
{
"scripts": {
"cs:update": "mkdir -p .ecs && cd .ecs && curl -O https://raw.githubusercontent.com/chevere/code-style/main/.ecs/ecs-chevere.php",
"ecs": "vendor/bin/ecs --config='.ecs/ecs.php'",
"ecs:check": "composer ecs check",
"ecs:fix": "composer ecs check --fix"
}
}
# Typing
# Type hinting
- All parameters, properties and return expressions must be type hinted
# Errors
Errors must be clear and concise, and must be evident where it came from.
- Markdown format
- One (1) line per error
# Code comments
Comments in logic should be used only in the following cases:
@codeCoverage
tags- Type hinting (for example, in loops)
# DocBlocks
DocBlock content should be short as possible, relevant and omit the obvious.
- Markdown format
@param
and@return
should be avoided (prefer type hinting)
← Quality Immutability →