One of Meumobi’s goals is keep the code clean, readable and maintainable. We have did this manually so far. In order to improve our quality we have been studying how to do this automatically. PHP Logo

Define a coding sytle

There are some coding styles available, but one of most famous is PHP Standard Recommendation (PSR) published by the PHP Framework Interop Group. Some members are from Zend and Laravel for example. The Recomendations 1 and 2 are about coding styles. PSR-1 comprises what should be considered the standard coding elements that are required to ensure a high level of technical interoperability between shared PHP code. PSR-2 considers PSR-1 and it is intended to reduce cognitive friction when scanning code from different authors. It does so by enumerating a shared set of rules and expectations about how to format PHP code. So we chose PSR-2.

Apply sytle in real time

There are some tools to help your work:

Check style after commits

If you have a public repository you can check your code free by StyleCI. It analyzes any commit and indicates how to fix.

Using StyleCI

  • Signup with github, and allow access to a repo that you want to fix code style;
  • Config:
    • Open https://styleci.io/repos/[repo_id]/settings and on configuration, add your config, preset: psr2 for this case;
    • You can create your own rules just have fun with the docs;
  • Use:
    • On https://styleci.io/repos/[repo_id] click in analyze now;
    • Then in show details, there are some options, like create a PR to fix the coding style;
    • Choose one, an enjoy;

Furthermore


Daniel Antonio Conte

Life, Universe, Everything

Follow me