Coding standards

Introduction

Coding standards help to improve the readability and the maintenance (time) of any project. Also, programmers may understand the code more quickly and thoroughly. Although there were coding standards in OXID eShop before we decided to introduce the PSR standard in order to standardize OXID eShop as a web application even more and to enforce the interoperability, esp. for libraries etc.

That’s why we defined this document as coding style guidelines to be used from OXID eShop version 4.9/5.2 on.

Please note that we’d highly appreciate if you followed these coding standards when contributing to the OXID eShop project.

PSR usage

  • From OXID eShop version 4.9/5.2 on we are using the PSR-1 and PSR-2 standard with some exceptions listed below.
  • We will use PSR-0 and PSR-4 standards from OXID eShop version 6.0 on.

Exceptions for PSR-1 and PSR-2 for OXID eShop version 4.9/5.2

  • We are not using namespaces (yet).
  • For PHP class files instead of StudlyCaps we are still using the “ox”-Prefix.
  • We still use ISO instead of UTF-8 (w/o BOM) as a character set in PHP files.
  • We still use the prefix underscore (_) for protected and private methods.
  • The so called “Hungarian notation” is used for variables and attributes.
  • Presently, there’s no limit for the line length.

PHPDoc

  • If a method returns something, the @return statement is required.
  • If a method returns nothing, do not enforce the @return null statement.

Help for developers

We published the following configuration files at GitHub: https://github.com/OXID-eSales/coding_standards

  • PHP CodeSniffer rules
  • PHPStorm autoformat config

In case of any questions about this topic, please feel free to ask at the developer mailing list.