Coding Style

OXID eShop uses PSR-2 as coding style. This guide shows you step by step, how PhpStorm can assist you with the coding style.

1. Installation of CodeSniffer

PhpStorm uses the command line tool CodeSniffer to detect coding style warnings and errors. When installing OXID eShop, CodeSniffer is installed by composer as well (if you did not specify the --no-dev switch on the command line). Check, this by executing CodeSniffer on the command line:


2. Configure PhpStorm to use CodeSniffer

  1. Install and configure PHP CodeSniffer in PhpStorm. This is described in the Jetbrains documentation (set code sniffer by remote interpreter if CodeSniffer is installed in VM. See Configure a PHP_CodeSniffer script associated with a PHP interpreter).

  2. PhpStorm has multiple profiles where you can configure, how PHP files should be inspected:

    1. Go to File ‣ Settings.

    2. Choose Editor ‣ Inspections

    3. Choose Profile: Project Default.

    4. Choose PHP ‣ Quality Tools and enable PHP Code Sniffer validation.

    5. Choose Coding standard: PSR12 (PSR12 needs CodeSniffer >=3.3.0).

  3. Configure the PhpStorm editor to use PSR2 as well:

    1. Go to File ‣ Settings.

    2. Choose Editor ‣ Code Style ‣ PHP

    3. Select Scheme: Project.

    4. Select Set from ‣ Predefined Style ‣ PSR12 (PSR12 needs CodeSniffer >=3.3.0).

3. Coding Style in Action

  • The PhpStorm editor shows you in every file via grey, serrated line where the coding style is corrupted.

  • PhpStorm can apply the coding style by reformatting existing code via Code ‣ Reformat Code.

  • You are able to run an inspection via Code ‣ Inspect Code. PhpStorm reports you CodeSniffer errors (and warnings if configured) in the section PHP ‣ Quality Tools.