This is set of sniffs and fixers that checks and fixes code of Nette Framework against Coding Standard in Documentation.
Install the tool globally:
composer global require nette/coding-standard
Check coding standard in folders src and tests:
ecs check src testsAnd fix it:
ecs fix src testsThe PHP version preset is automatically detected from your project's composer.json. If auto-detection is not possible, you can specify it manually:
ecs check src tests --preset php81You can tweak 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.
ncs.php returns an associative array of fixer overrides:
<?php
return [
'strict_comparison' => false,
'PhpCsFixerCustomFixers/commented_out_function' => false, // don't comment out dump(), var_dump(), ...
];ncs.xml is a PHP_CodeSniffer ruleset. It does not need to reference the version preset – it is automatically combined with it. Use $presets/ to reference any bundled preset:
<?xml version="1.0"?>
<ruleset name="MyProject">
<!-- Optional: enable use function/const imports -->
<rule ref="$presets/optimize-fn.xml"/>
<!-- Disable a rule -->
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint"/>
</ruleset>For one-off runs (e.g. when you want to keep dump() calls intact during debugging) you can point to an additional config file without committing it to the project:
ecs fix src --config-file ./my-overrides.phpThe tool is selected by extension: .php applies to PHP CS Fixer, .xml to PHP_CodeSniffer. You can pass --config-file twice to configure both tools. Project-level ncs.php/ncs.xml are still used; values from --config-file take precedence.
# .github/workflows/coding-style.yml
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: 8.1
- run: composer create-project nette/coding-standard temp/coding-standard
- run: php temp/coding-standard/ecs check src tests