Skip to content

Latest commit

 

History

History
58 lines (39 loc) · 1.54 KB

coding-standard-php.md

File metadata and controls

58 lines (39 loc) · 1.54 KB

Sunray PHP Coding Standard

We basically follow the coding style related PSR standards issued by the PHP Framework Interoperability Group:

Differences/Addendums from PSR

Spaces around concatenation

The string concatenation operator MUST be preceded and followed by a space.

// bad
$string = 'Hello '.$name;

// good
$string = 'Hello ' . $name;

Scalar type hints

Scalar values should use short/abbreviated form in all applicable locations including function parameter type hints, function return types, and annotations.

// bad
private function (integer $timeout, string $phrase, boolean $enabled)

// good
private function (int $timeout, string $phrase, bool $enabled)

Naming

About the names of identifiers like classes, functions, methods, variables:

  • A name SHOULD be descriptive, distinctive, precise and readable.
  • A name SHOULD NOT be abbreviated.

A long name is not a problem, since our IDE has auto completion.

Inter-line alignment

Consecutive assignments or declarations SHOULD NOT be aligned. Adding one item may require you to re-align the other items, resulting in unnecessary changes in your commit.

// bad
$short        = 1;
$veryLongItem = 2;

// good
$short = 1;
$veryLongItem = 2;