-
Notifications
You must be signed in to change notification settings - Fork 34
Style Guidelines
To make sure the code stays clean and not everyone does things their own way, we have decided to setup style guidelines regarding conventions and standards when contributing to our codebase.
PSRs are the de facto standard when it comes to programming in PHP. We follow PSR-1 and PSR-12 with some additional MUSTs.
When argument/parameter lists are split across multiple lines they MUST have a trailing comma. This applies to function/method calls and declarations:
<?php
namespace Vendor\Package;
class ClassName
{
public function aVeryLongMethodName(
ClassTypeHint $arg1,
&$arg2,
array $arg3 = [],
): void {
$arg1->anotherLongMethodName(
$arg3,
'value',
);
}
}
And the following would not be allowed:
<?php
namespace Vendor\Package;
class ClassName
{
public function aVeryLongMethodName(
ClassTypeHint $arg1,
&$arg2,
array $arg3 = []
): void {
$arg1->anotherLongMethodName(
$arg3,
'value'
);
}
}
When using the #[SensitiveParameter]
attribute, it MUST be on a separate line:
<?php
namespace Vendor\Package;
class ClassName
{
public function sensitiveMethod(
#[SensitiveParameter]
string $someParameter,
#[SensitiveParameter]
object $object,
): void {
<?php
namespace Vendor\Package;
class ClassName
{
public function sensitiveMethod(
#[SensitiveParameter]
string $parameter,
): bool {
When using named arguments for a function call, arrays MUST not be expanded. This preserves readability:
$this->acl->allow(
roles: 'guest',
resources: 'company',
privileges: ['viewBanner', 'viewFeatured'],
);
#[OneToOne(
targetEntity: CompanyLocalisedText::class,
cascade: ['persist', 'remove'],
orphanRemoval: true,
)]
#[JoinColumn(
name: 'description_id',
referencedColumnName: 'id',
nullable: false,
)]
protected CompanyLocalisedText $description;
Conditions in control structures MUST be written in Yoda style:
if (null === $value) {
And the following would not be allowed:
if ($value === null) {
Identical comparison MUST be used, unless type juggling is necessary:
if (null === $value) {
And the following would not be allowed:
if (null == $value) {
- Contributing
- Architecture
- Components
- View helpers
- Sub-projects
- Archive