Skip to content

A php coding standard for PHP CodeSniffer, that does not suck.

License

Notifications You must be signed in to change notification settings

intxcc/ActuallyGoodPhpCS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ActuallyGoodPhpCS

A php coding standard, that does not suck.

I code a lot with JS and use eslint with standardJS. As there is no Coding Standard, that is ever so slightly near that, so I created one.

Important was, that the coding standard is supported by a linter that runs with VS Code, as this is my main development IDE.

Have fun with it and give love to the projects, this does depend on ♥

How to install

3rd party dependencies

To install

  • Clone this repo to your local machine
  • Now set the installed_paths of phpcs to find this and the unused variable standard. For this execute following code (In case you want to install globally):

HINT: Installed paths needs to get a comma seperated list of the paths of all standards, beside the in-built.

phpcs --config-set installed_paths "<GLOBAL_COMPOSER_PATH>\Composer\vendor\sirbrillig\phpcs-variable-analysis,<PATH_OF_THIS_REPO>\ActuallyGoodPhpCS"

Language features

Supported

  • Max line length 120 chars
  • Linux line endings "\n"
  • Force single quotes, if there is no variable in the string
  • Newline at end of file
  • Space after function name and after parantheses. Curly brace on same line.
  • Force 1 tab intendention
  • Enforce short array declarations
  • Force array formatting
    • Single line array, with spaces after every comma
    • Multi line array, with only one value per line and not on the same line as the opening bracket
  • No duplicate class names
  • FIXMEs will be shown as error, so you won't forget it
  • TODOs will be shown as warnings, so you won't forget these either
  • No inline control structures (e.g. Inline if statements)
  • No unnecessary string concat
'Hello' . 'World' // This is not allowed
  • Force camel case of method names
  • Force camel case of memeber variables
  • Disallow deprecated functions
  • Force lowercase for:
    • Constants
    • Types
    • Keywords
  • Forbid any character before PHP opening tag
  • Forbid these functions:
    • delete
    • sizeof
  • Show warning for all unused variables
  • Force "elseif" instead of "else if"
  • No unnecessary whitespace
  • Enforce doc comment formatting
  • Check for BOM
  • Forbid multiple statements in one line
  • Space required after type cast
  • Forbid PHP4 constructors
  • Warning if nesting level is bigger than 5
  • Error if nesting level is bigger than 10
  • Forbid silencing of errors
  • Other cool stuff. Look in the phpcs.xml, the comments in there descibe all includes.
  • Space surrounding dots to concat strings
  • Forbid empty lines at end or beginning of function and class declaration
  • Force function and variable names not in classes to snake_case

Planned features

  • Multi line if statement formatting
  • Forbid multiple empty lines in whole file
  • dirname(FILE) => DIR
  • No content on same line as after closing brace
  • Allow intances of classes in camelCase

ToDo

  • Make all functions declared in this standard conform to the standard

Feel free to send me pull requests.

Only changes are allowed that bring this standard closer to standardJS. (Except the omission of semicolons of course)

About

A php coding standard for PHP CodeSniffer, that does not suck.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages