How to Apply Nette Coding Standard in Your Project

This post was updated at December 2018 with fresh know-how.
What is new?

Updated to Nette CodingStandard 2.0 and EasyCodingStandard 5.

Pull-requests are more fun thanks to automated coding standard. You don't have explain where to put space or bracket. You can talk about architecture or meaning of the code instead. Moreover in open-source. I wanted to make this possible in Nette, but Coding Standards could be found only in documentation.

This year I started to work on a Nette Coding Standard (NCS) that you can put to CLI. And you'll be able set it up in in your project yourself today.

Nette\CodingStandard 2.0 was released 2 months. This version is ready to use, includes all important checkers and is used on all Nette\* packages in Travis.

NCS checks every pull-request you make to Nette:

All that need is to define stage in travis.yml:

That's it! Just 2 commands and it checks any project you have.

But first...

PHP 7.1+

This packages requires PHP 7.1 to run as the rest of the Nette (mostly current master or 3.0).

If you still don't know why should you **join Symfony, Nette, Doctrine, Zend or Sylius. You can read this post or wait a bit longer. It's up to you.

Setup Your Project

Install the package to your dev dependencies:

composer require nette/coding-standard --dev

Good! Now just pick the prepared set.

At the moment there are 3 configs with set of checkers:

Just pick the one that suits you:

vendor/bin/ecs check src tests --config vendor/nette/coding-standard/coding-standard-php71.yml

Then, fix the code:

vendor/bin/ecs check src tests --config vendor/nette/coding-standard/coding-standard-php71.yml --fix

Config with higher PHP version includes all lower versions, so with coding-standard-php71.yml you cover the other 2 configs as well.

Happy coding!

Do you learn from my contents or use open-souce packages like Rector every day?
Consider supporting it on GitHub Sponsors. I'd really appreciate it!