Coding standards - mattacosta/php-parser GitHub Wiki

1. Lines

  • Should only contain a single statement.
  • Should be limited to 80 characters if possible.
    • If a statement exceeds 120 characters, it should be split into multiple statements.

2. Whitespace

2.1 Files

  • Should use an indent of 2 spaces.
  • Should end in a single empty line.

2.2 Lines

  • Should not have trailing spaces.

2.3 Comments

  • There should be a single empty line before a documentation comment that spans multiple lines.

2.4 Operators

  • There should be a single space before and after binary operators.
  • There should not be any whitespace between a unary operator and its operand.

2.5 Statements

2.5.1 Argument and parameter lists

  • Should not have whitespace after the ( or before the ).

2.5.2 Array declarations

  • Should not have whitespace between the [ and first element or last element and ].
    • If the line exceeds 80 characters, each element may be placed on its own line and indented one level.

2.5.3 Class and interface declarations

  • Should have a single space between the last identifier and {.
  • Should have a single empty line after the { and before the }.

2.5.4 Control structures

  • Should have a single space between the keyword and ( or {.
  • Should have a single space between the ) and {.
  • Should not have whitespace after the ( or before the ).

2.5.5 Function declarations

  • Should have a single space between the ) and {.

2.5.6 Invocations

  • Should not have whitespace between the identifier and (.
  • Should not have whitespace between the ) and ;.

3. Classes

3.1 Modifiers

  • All class members except constructors must include a visibility modifier.

4. Semicolons

All statements must end in a semicolon.

5. Strings

Single-quoted strings should be used by default.

6. Variables

All variable declarations must use let or const.

7. Naming conventions

7.1 General

  • Only the first letter of acronyms should be uppercase.

7.2 Class and interface names

  • Should use UpperCamelCase.
  • Interfaces should start with an I.
  • Test classes should end with Test.

7.3 Class member names

7.3.1 Methods

  • Should use lowerCamelCase.

7.3.2 Properties

  • Should use lowerCamelCase.
  • Should not start with an _ unless it is protected or private and a public getter or setter exists with the same name.

7.4 Function names

  • Should use lowerCamelCase.

7.5 Variable names

  • Should use lowerCamelCase.