- How do I install MO4 Coding Standard in my Laravel project?
- Run `composer require --dev mayflower/mo4-coding-standard` in your project directory. No additional setup is needed beyond configuring PHP_CodeSniffer to use the MO4 standard in your `.phpcs.xml` or `phpcs.xml.dist` file.
- Does this package work with Laravel 10+?
- Yes, MO4 Coding Standard requires PHP 8.1+, which aligns with Laravel 10+'s PHP version requirements. It’s fully compatible with modern Laravel projects.
- Can I use MO4 alongside PSR12 in Laravel?
- Yes, but you’ll need to configure PHP_CodeSniffer to prioritize MO4 rules where needed. Some rules (e.g., array alignment) may conflict with PSR12, so test thoroughly or disable redundant rules in `ruleset.xml`.
- How do I configure use statement sorting order?
- Edit your `phpcs.xml` or `ruleset.xml` to specify the `order` property for `MO4.Formatting.AlphabeticalUseStatements`. Options include `locale`, `string-locale`, or custom dictionaries. Example: `<arg name="order" value="string-locale"/>`.
- Will this break my existing Laravel codebase?
- It depends on your current coding style. Run `vendor/bin/phpcs --standard=MO4 --report=full app/` first to identify violations. Use `phpcbf` for auto-fixing supported rules, but review changes manually for Laravel-specific patterns (e.g., Blade templates).
- Can I exclude Blade templates or migrations from MO4 checks?
- Yes, configure exclusions in your PHP_CodeSniffer config. Example: `<file>app/</file><exclude name="app/Views"/><exclude name="database/migrations"/>` to skip Blade and migrations.
- How do I integrate MO4 into GitHub Actions for CI?
- Add a step to your workflow like this: `- name: Run MO4 Coding Standard run: vendor/bin/phpcs --standard=MO4 --warning-severity=9 --error-severity=9 app/`. Treat violations as errors (`--error-severity=9`) to block PRs or warnings (`--warning-severity=9`) for gradual adoption.
- Are there Symfony-specific rules I should disable for Laravel?
- Yes, disable redundant Symfony rules like `Symfony2.Arrays.TrailingComma` if they conflict with Laravel conventions. Use `<rule ref="Symfony" />` in your `ruleset.xml` and exclude specific rules with `<exclude name="Symfony2.Arrays.TrailingComma" />`.
- Does MO4 support auto-fixing (phpcbf) for Laravel code?
- Most rules support auto-fixing via `phpcbf`. Run `vendor/bin/phpcbf --standard=MO4 app/` to fix alignable arrays, use statements, and docblocks. Test in a staging environment first, as some Laravel-specific patterns (e.g., dynamic Blade strings) may not auto-fix cleanly.
- What alternatives exist for Laravel coding standards?
- Alternatives include `phpcs-standard` (PSR12), `dealerdirect/phpcodesniffer-composer-normalize`, or custom rulesets. MO4 is unique for its Symfony extension (e.g., strict docblocks, array alignment) and configurability, making it ideal for projects using Symfony components alongside Laravel.