PHPackages                             nette/coding-standard - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. nette/coding-standard

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

nette/coding-standard
=====================

v3.5.1(2mo ago)41937.1k—3.1%13[4 PRs](https://github.com/nette/coding-standard/pulls)15MITPHPPHP ^8.0

Since Jul 6Pushed 4w ago10 watchersCompare

[ Source](https://github.com/nette/coding-standard)[ Packagist](https://packagist.org/packages/nette/coding-standard)[ RSS](/packages/nette-coding-standard/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (12)Versions (48)Used By (15)

Nette Coding Standard code checker &amp; fixer
==============================================

[](#nette-coding-standard-code-checker--fixer)

[![Downloads this Month](https://camo.githubusercontent.com/c8bf955ca2ab91e9da31de7311c8b36be9c4c2ae4b178b9f2bd2c299d4e47c59/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6e657474652f636f64696e672d7374616e646172642e737667)](https://packagist.org/packages/nette/coding-standard)[![Latest Stable Version](https://camo.githubusercontent.com/d78d314d3be8e4455fc6952799f43980831701fd48306bd6813b877302ef90bb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e657474652f636f64696e672d7374616e646172642e737667)](https://github.com/nette/coding-standard/releases)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](/LICENSE)

Introduction
------------

[](#introduction)

Nette Coding Standard checks and automatically fixes your PHP code so that it follows the [Nette coding standard](https://doc.nette.org/contributing/coding-standard) – from indentation and braces to spacing and the ordering of imports.

Under the hood it combines two industry-standard tools, [PHP CS Fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer) and [PHP\_CodeSniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer), preconfigured with the full Nette rule set, so you don't have to configure anything yourself. It also ships rules for the latest PHP versions and applies them incrementally based on the PHP version your project uses.

It runs as a standalone application, not as a project dependency, which keeps its many dependencies away from your own.

Documentation can be found on the [website](https://doc.nette.org/tools/coding-standard). If you like it, **[please make a donation now](https://github.com/sponsors/dg)**. Thank you!

Installation
------------

[](#installation)

Install it globally via Composer:

```
composer global require nette/coding-standard
```

Make sure your global Composer `bin` directory is in your [`PATH`](https://getcomposer.org/doc/03-cli.md#global). The `ecs` command is then available from anywhere, on any operating system.

Alternatively, install it as a standalone project, which is handy for pinning a specific version in CI:

```
composer create-project nette/coding-standard
```

It requires PHP 8.0 or higher.

Usage
-----

[](#usage)

The tool provides two commands. The `check` command runs in read-only mode and only reports violations, while `fix` repairs them automatically:

```
ecs check
ecs fix
```

Without any arguments it scans the `src` and `tests` directories. You can also pass one or more of your own paths:

```
ecs check app bin
```

**Back up your files first**, or run `fix` on a clean working tree so you can review the changes afterwards with `git diff`.

In read-only mode the tool exits with a non-zero code when any violation is found, so it fits nicely into CI pipelines.

### PHP Version

[](#php-version)

The tool supports PHP 8.0 to 8.5 and applies the rules incrementally according to the version. The version preset is detected automatically from your project's `composer.json`. If auto-detection is not possible, specify it manually:

```
ecs check --preset php81
```

### Custom Configuration

[](#custom-configuration)

You can tweak the rules per-project by placing `ncs.php` (PHP CS Fixer) and/or `ncs.xml` (PHP\_CodeSniffer) in your project root. Both are discovered automatically and merged on top of the preset, with your values taking precedence.

**`ncs.php`** returns an associative array of fixer overrides:

```
