Documentation

3.3 PSR-2

Integrated uses the PSR-2 coding standard. PSR-2 makes code easier to read and will help developers to code in a unified way.

What is PSR-2?

PSR-2 is a code style that all frameworks and libraries will be able to be use with the same syntax. The code will also look clean and structured because PSR-2 uses certain rules:

  • Code MUST follow a "coding style guide" PSR (see PSR-1).
  • Code MUST use 4 spaces for indenting, not tabs.
  • There MUST NOT be a hard limit on line length; the soft limit MUST be 120 characters; lines SHOULD be 80 characters or less.
  • There MUST be one blank line after the namespace declaration, and there MUST be one blank line after the block of use.
  • Opening braces for classes MUST go on the next line, and closing braces MUST go on the next line after the body.
  • Opening braces for methods MUST go on the next line, and closing braces MUST go on the next line after the body.
  • Visibility MUST be declared on all properties and methods;abstract and final MUST be declared before the visibility; static MUST be declared after the visibility.
  • Control structure keywords MUST have one space after them; method and function calls MUST NOT.
  • Opening braces for control structures MUST go on the same line, and closing braces MUST go on the next line after the body.
  • Opening parentheses for control structures MUST NOT have a space after them, and closing parentheses for control structures MUST NOT have a space before.

Why PSR-2?

Using PSR-2 will make programming a whole lot easier, your code will look more structured and neat and it will be easier and faster to use other program languages in your code. So, what are you waiting for?

Install and set up PSR-2

First install PHP on your local machine, including code sniffer.

Now you can set up PSR-2 in PHPStorm:

  • Go to Settings(ctrl+alt+s)
  • Go to Languages & Frameworks->PHP->Code Sniffer->button behind Configuration->set path (if you used the PHP quick setupm the path is C:\php-cs\vendor\bin\phpcs.bat)
  • Go to Editor->Inspections ->Profile: Default (do not use Project Default, unless you want to use it for the current project only)->PHP->Code Sniffer + mess detector -> on. For Code Sniffer set code standard to PSR2.