Code Quality & Tooling
Tooling packages provide code quality enforcement and development utilities.
phpstan-rules
Section titled “phpstan-rules”Centralized PHPStan static analysis configuration and custom rules.
Key Features
Section titled “Key Features”- Level 8 analysis (strictest)
- Custom naming convention rules
- Aggregated PHPStan extensions
- Laravel-specific analysis via Larastan
Custom Rules
Section titled “Custom Rules”| Rule | Enforces |
|---|---|
AssignVariableRule | Variables in snake_case |
ParameterRule | Parameters in snake_case |
MethodRule | Methods in camelCase |
ClassRule | Classes in StudlyCase |
ClassConstRule | Constants in UPPER_CASE |
PropertyRule | Properties in snake_case |
PromotedPropertyRule | Promoted properties in snake_case |
DisallowModifyLocalStaticVariableRule | No modifying local statics |
RedundantVarAnnotationRule | No redundant @var |
DisallowCacheForeverExceptInMemoryCacheDriverRule | Restrict cache forever |
Included Extensions
Section titled “Included Extensions”larastan/larastan- Laravel framework analysisphpstan/phpstan-deprecation-rules- Deprecation detectionphpstan/phpstan-strict-rules- Strict type rulesphpstan/phpstan-mockery- Mockery supportshipmonk/phpstan-rules- Additional rulesspaze/phpstan-disallowed-calls- Function blockingekino/phpstan-banned-code- Banned patternsthecodingmachine/phpstan-safe-rule- Safe library integration
Configuration
Section titled “Configuration”# phpstan.neonincludes: - vendor/rightcapital/phpstan-rules/project-extensions.neonFor PHP packages:
includes: - vendor/rightcapital/phpstan-rules/laravel-package-extensions.neoncomposer phpstan # Runs: vendor/bin/phpstan analyse --ansirector-rules
Section titled “rector-rules”Automated code refactoring with Rector.
Key Features
Section titled “Key Features”- PHP 8.3/8.4 automatic upgrades
- Laravel Facade alias conversion
#[Override]attribute addition- Test case finalization
Custom Rules
Section titled “Custom Rules”| Rule | Purpose |
|---|---|
UseFullyQualifiedClassNameFacadeRector | Convert Facade aliases to FQCNs |
Included Rule Sets
Section titled “Included Rule Sets”Rector\Php83- PHP 8.3 upgradesRector\Php84- PHP 8.4 upgradesAddOverrideAttributeToOverriddenMethodsRector- Add#[Override]FinalizeTestCaseClassRector- Finalize test cases
Configuration
Section titled “Configuration”return (require 'vendor/rightcapital/rector-rules/rector.rules.php')( paths: ['app', 'src'], ignore_list: ['vendor', 'config']);# Dry run (CI)vendor/bin/rector process --dry-run
# Apply changesvendor/bin/rector processphp-cs-fixer-rules
Section titled “php-cs-fixer-rules”PHP-CS-Fixer configuration with RightCapital code style.
Key Features
Section titled “Key Features”- PSR-12 + Symfony standard base
- Custom fixer registration
- Parallel execution support
- CI/CD integration
Included Rule Sets
Section titled “Included Rule Sets”@PSR12- PSR-12 standard@Symfony- Symfony coding standard@Symfony:risky- Risky Symfony rules@PHP8x2Migration- PHP 8.2 migration
Configuration
Section titled “Configuration”$finder = PhpCsFixer\Finder::create() ->exclude(['bootstrap', 'config', 'storage']) ->in(__DIR__);
return (require 'vendor/rightcapital/php-cs-fixer-rules/.php-cs-fixer.rules.php')($finder);# Check stylevendor/bin/php-cs-fixer fix --dry-run --diff
# Fix stylevendor/bin/php-cs-fixer fixphp-cs-fixer-custom-fixers
Section titled “php-cs-fixer-custom-fixers”9 custom PHP-CS-Fixer implementations.
Custom Fixers
Section titled “Custom Fixers”| Fixer | Purpose |
|---|---|
BlankLineAfterStatementFixer | Blank lines after do/for/if/switch/while |
BlankLineAfterTraitUsesFixer | Blank line after trait imports |
BlankLineAfterEnumCasesFixer | Blank line after enum cases |
NoMultipleConditionalExpressionsPerLineFixer | One condition per line |
NoSpaceAfterCommaInPhpdocArrayFixer | No spaces in PHPDoc arrays |
SpaceBeforeSingleLineCommentFixer | Space before inline comments |
UseFullyQualifiedClassNameInPhpdocFixer | FQCNs in PHPDoc |
NumericLiteralSeparatorFixer | Underscores in numbers (1_000_000) |
ReadonlyAfterVisibilityInConstructorPromotionFixer | public readonly order |
Registration
Section titled “Registration”$config->registerCustomFixers([ new BlankLineAfterStatementFixer(), new NumericLiteralSeparatorFixer(), // ...])->setRules([ 'RightCapital/blank_line_after_statement' => true, 'RightCapital/numeric_literal_separator' => true,]);composer-normalize
Section titled “composer-normalize”Normalize composer.json files for consistent formatting.
Key Features
Section titled “Key Features”- Package list sorting
- JSON structure validation
- Dry-run and diff modes
- Customizable indentation
# Check (CI)./vendor/bin/composer-normalize normalize --dry-run
# Fix./vendor/bin/composer-normalize normalize
# Custom indentation./vendor/bin/composer-normalize normalize --indent-style tab --indent-size 1Options
Section titled “Options”| Option | Purpose |
|---|---|
--diff | Show changes |
--dry-run | Preview only |
--indent-size N | Indent size |
--indent-style space|tab | Indent style |
--no-update-lock | Skip lock update |
composer-event-dispatcher
Section titled “composer-event-dispatcher”Bridge between Composer events and Laravel event bus.
Key Features
Section titled “Key Features”- Composer lifecycle event handling
- Laravel event dispatching
- IDE helper integration
Configuration
Section titled “Configuration”{ "scripts": { "post-autoload-dump": [ "@php artisan package:discover --ansi", "RightCapital\\ComposerEventDispatcher\\ComposerEventDispatcher::handle" ] }}Event Flow
Section titled “Event Flow”- Composer triggers
post-autoload-dump ComposerEventDispatcher::handlecalled- Event converted to Laravel
ComposerEvent - Registered listeners respond (IDE helpers, etc.)
ide-helper-files-generator
Section titled “ide-helper-files-generator”Automatic IDE helper file generation on Composer events.
Key Features
Section titled “Key Features”- Triggered by
post-autoload-dump - Only runs in development
- Generates autocomplete files
Generated Files
Section titled “Generated Files”_ide_helper.php- Facade autocomplete_ide_helper_models.php- Model property hints.phpstorm.meta.php- PhpStorm metadata
Installation
Section titled “Installation”composer require --dev rightcapital/ide-helper-files-generatorNo additional configuration needed - auto-discovered via service provider.
Dependencies
Section titled “Dependencies”barryvdh/laravel-ide-helperrightcapital/composer-event-dispatcher
env-sync
Section titled “env-sync”Synchronize environment variables between .env.local and .env.
Key Features
Section titled “Key Features”- Smart merge with conflict detection
- Interactive and non-interactive modes
- Missing key detection
- Value comparison
# Interactive modephp vendor/bin/env-sync
# Non-interactive (CI/CD)php vendor/bin/env-sync --no-interactionSync Logic
Section titled “Sync Logic”| Scenario | Action |
|---|---|
Missing .env | Copy .env.local |
| Missing keys | Append from .env.local |
| Conflicting values | Prompt user (interactive) |
| Identical values | No action |
Interactive Example
Section titled “Interactive Example”Found conflicting values:
APP_DEBUG: .env: false .env.local: true Update .env with .env.local value? [Y/n]:CI/CD Integration
Section titled “CI/CD Integration”GitLab CI Pipeline
Section titled “GitLab CI Pipeline”# PHPStanphpstan: script: - vendor/bin/phpstan analyse --ansi
# Rectorrector: script: - vendor/bin/rector process --dry-run
# PHP-CS-Fixerphp cs fixer: script: - vendor/bin/php-cs-fixer fix --dry-run --diff
# Composer Normalizecomposer normalize: script: - ./libs/composer-normalize/bin/composer-normalize normalize --dry-run -nSummary
Section titled “Summary”| Package | Type | Purpose |
|---|---|---|
| phpstan-rules | Static analysis | Type checking, naming conventions |
| rector-rules | Refactoring | PHP version upgrades, code cleanup |
| php-cs-fixer-rules | Code style | Formatting configuration |
| php-cs-fixer-custom-fixers | Code style | 9 custom fixers |
| composer-normalize | Tooling | composer.json formatting |
| composer-event-dispatcher | Bridge | Composer-Laravel event bridge |
| ide-helper-files-generator | Development | IDE autocomplete |
| env-sync | Utility | Environment sync |