automattic/phpcs-neutron-standard
Install Dependencies
composer require --dev squizlabs/php_codesniffer dealerdirect/phpcodesniffer-composer-installer automattic/phpcs-neutron-standard
For a pre-configured ruleset (including WordPress standards), use:
composer require --dev automattic/phpcs-neutron-ruleset
Configure phpcs.xml
Add this to your project’s root:
<?xml version="1.0"?>
<ruleset name="ProjectStandard">
<rule ref="NeutronStandard"/>
<!-- Optional: Extend with WordPress standards -->
<rule ref="WordPress"/>
</ruleset>
First Run Lint a file with sniff codes (critical for debugging):
vendor/bin/phpcs -s src/MyClass.php
Use this to catch:
declare(strict_types=1)).maxFunctionLines).function foo():int vs. function foo(): int).CI Integration Add to your CI pipeline (e.g., GitHub Actions):
- name: Run PHP_CS_Fixer
run: vendor/bin/phpcs --standard=NeutronStandard --warning-severity=0 src/
Fail builds on warnings by omitting --warning-severity=0.
Editor Integration Configure your IDE (PHPStorm, VSCode) to use:
Settings > Languages & Frameworks > PHP > Code Sniffer → Set standard to NeutronStandard.settings.json:
"php-cs-fixer.executablePath": "vendor/bin/php-cs-fixer",
"php-cs-fixer.rules": "@NeutronStandard"
Custom Rulesets
Override defaults in phpcs.xml:
<ruleset>
<rule ref="NeutronStandard">
<arg name="maxFunctionLines" value="50"/> <!-- Customize max lines -->
<exclude name="DisallowGlobalFunctionsSniff"/> <!-- Disable a rule -->
</rule>
</ruleset>
NeutronRuleset for a pre-configured mix of Neutron + WordPress rules.php-cs-fixer for automated fixes (e.g., spacing, newlines):
composer require --dev friendsofphp/php-cs-fixer
vendor/bin/php-cs-fixer fix --rules=@NeutronStandard src/
vendor/bin/phpcs src/ --standard=NeutronStandard --extensions=php
PHP Version Mismatch
TypeHintSniff failures may occur if using PHP <7.4.php.ini and CI environment use PHP ≥7.4.Strict Types Enforcement
RequireStrictTypesSniff ignores interfaces (per design). False positives may appear in interface files.phpcs.xml:
<rule ref="NeutronStandard.RequireStrictTypesSniff">
<exclude pattern="#^.*\.php$#"/>
</rule>
False Positives in Generators
TypeHintSniff may flag generator return types (e.g., Generator<int, string>) as invalid.Cache Issues
vendor/bin/phpcs --config-set installed_paths vendor/automattic/phpcs-neutron-standard
Editor Plugin Quirks
NeutronStandard. Manually specify the path:
vendor/automattic/phpcs-neutron-standard
-v to debug rule application:
vendor/bin/phpcs -v src/MyClass.php
vendor/bin/phpcs --standard=NeutronStandard/TypeHint src/MyClass.php
--severity to filter errors:
vendor/bin/phpcs --severity=warning src/
Custom Sniffs
Extend the standard by adding your own sniffs to phpcs.xml:
<rule ref="NeutronStandard"/>
<rule ref="./custom-sniffs/MySniff.php"/>
Override Rule Properties Modify rule behavior dynamically:
<rule ref="NeutronStandard.DisallowLongformArraySniff">
<properties>
<property name="allowedPatterns" value="\['a', 'b'\]"/>
</properties>
</rule>
Exclude Files/Directories Skip specific paths:
<file>src/</file>
<exclude-pattern>.*/tests/.*</exclude-pattern>
phpstan:
Combine with PHPStan for static analysis:
composer require --dev phpstan/phpstan
vendor/bin/phpstan analyse --level=max src/
phpcs.xml to explain rule rationale:
<!-- NeutronStandard enforces strict types for type safety -->
<rule ref="NeutronStandard.RequireStrictTypesSniff"/>
time vendor/bin/phpcs --standard=NeutronStandard src/
How can I help you explore Laravel packages today?