mayflower/mo4-coding-standard
PHP_CodeSniffer ruleset for the MO4 coding standard. Extends Symfony’s standard with extra sniffs for array formatting (alignment, multiline rules), property docblocks (@var), and lexicographically sorted use statements (configurable ordering).
mo4-coding-standard is a PHP_CodeSniffer (PHPCS) ruleset that extends the Symfony Coding Standard, making it highly compatible with Laravel projects (which are PHP-based and often use Symfony components). It enforces consistent coding style, reducing cognitive load for developers and improving maintainability.AlphabeticalUseStatements sorting order), enabling alignment with existing team conventions or Laravel-specific best practices.phpcbf, reducing manual refactoring effort.composer require --dev mayflower/mo4-coding-standard) is straightforward and integrates seamlessly with Laravel’s existing tooling (e.g., PHPStan, Pest, or custom CI pipelines).MO4.WhiteSpace.MultipleEmptyLines) may conflict with Laravel’s Blade templates or legacy codebases. Risk mitigation:
resources/views) via PHPCS configuration.--parallel).MO4.Strings.VariableInDoubleQuotedString may flag Blade syntax ({{ $var }}) as violations. Risk mitigation:
app/, src/)?{ $var } syntax, array alignment)?phpcbf) be used preemptively or reactively?npm scripts or custom tasks.phpcs command).pest.php hooks).app/Http/Controllers) and enforce MO4 there.phpcs --diff to compare against baseline and measure impact.AlphabeticalUseStatements, ArrayDoubleArrowAlignment (low friction).VariableInDoubleQuotedString, PropertyComment (higher impact).MultipleEmptyLines).phpcbf in pre-commit hooks (e.g., Husky) or CI to auto-correct fixable issues.composer require --dev mayflower/mo4-coding-standard
./vendor/bin/phpcbf app/Http --standard=MO4
.phpcs.xml:
<arg name="exclude" value="resources/views,storage"/></arg>
MO4.WhiteSpace.MultipleEmptyLines for Blade:
<rule ref="MO4.WhiteSpace.MultipleEmptyLines">
<properties>
<property name="exclude" value="\.blade\.php$"/></property>
</properties>
</rule>
composer.json:
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"require-dev": {
"phpcsstandards/phpcs": "^4.0",
"mayflower/mo4-coding-standard": "^11.0"
}
~/.phpcs.dist or project-specific .phpcs.xml)..phpcs.xml:
<?xml version="1.0"?>
<ruleset>
<config name="installed_paths" value="./vendor/mayflower/mo4-coding-standard"/>
<config name="default_standard" value="MO4"/>
<config name="encoding" value="utf-8"/>
<file>app/</file>
</ruleset>
./vendor/bin/phpcs --standard=MO4 --report=full app/ to baseline violations.phpcbf to resolvable issues before enforcement.- name: Run PHPCS
run: ./vendor/bin/phpcs --standard=MO4 --warning-severity=3 app/
# package.json
"scripts": {
"lint:php": "phpcs --standard=MO4 --report=emacs app/"
}
Illuminate\Support\Facades usage.{ $var } in strings?").ruleset.xml or exclude files.--parallel flag or split by directory.app/, src/) before full rollout.How can I help you explore Laravel packages today?