Skip to content

Code Quality & Tooling

Tooling packages provide code quality enforcement and development utilities.

Centralized PHPStan static analysis configuration and custom rules.

  • Level 8 analysis (strictest)
  • Custom naming convention rules
  • Aggregated PHPStan extensions
  • Laravel-specific analysis via Larastan
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
  • larastan/larastan - Laravel framework analysis
  • phpstan/phpstan-deprecation-rules - Deprecation detection
  • phpstan/phpstan-strict-rules - Strict type rules
  • phpstan/phpstan-mockery - Mockery support
  • shipmonk/phpstan-rules - Additional rules
  • spaze/phpstan-disallowed-calls - Function blocking
  • ekino/phpstan-banned-code - Banned patterns
  • thecodingmachine/phpstan-safe-rule - Safe library integration
# phpstan.neon
includes:
- vendor/rightcapital/phpstan-rules/project-extensions.neon

For PHP packages:

includes:
- vendor/rightcapital/phpstan-rules/laravel-package-extensions.neon
Terminal window
composer phpstan # Runs: vendor/bin/phpstan analyse --ansi

Automated code refactoring with Rector.

  • PHP 8.3/8.4 automatic upgrades
  • Laravel Facade alias conversion
  • #[Override] attribute addition
  • Test case finalization
Rule Purpose
UseFullyQualifiedClassNameFacadeRector Convert Facade aliases to FQCNs
  • Rector\Php83 - PHP 8.3 upgrades
  • Rector\Php84 - PHP 8.4 upgrades
  • AddOverrideAttributeToOverriddenMethodsRector - Add #[Override]
  • FinalizeTestCaseClassRector - Finalize test cases
rector.php
return (require 'vendor/rightcapital/rector-rules/rector.rules.php')(
paths: ['app', 'src'],
ignore_list: ['vendor', 'config']
);
Terminal window
# Dry run (CI)
vendor/bin/rector process --dry-run
# Apply changes
vendor/bin/rector process

PHP-CS-Fixer configuration with RightCapital code style.

  • PSR-12 + Symfony standard base
  • Custom fixer registration
  • Parallel execution support
  • CI/CD integration
  • @PSR12 - PSR-12 standard
  • @Symfony - Symfony coding standard
  • @Symfony:risky - Risky Symfony rules
  • @PHP8x2Migration - PHP 8.2 migration
.php-cs-fixer.php
$finder = PhpCsFixer\Finder::create()
->exclude(['bootstrap', 'config', 'storage'])
->in(__DIR__);
return (require 'vendor/rightcapital/php-cs-fixer-rules/.php-cs-fixer.rules.php')($finder);
Terminal window
# Check style
vendor/bin/php-cs-fixer fix --dry-run --diff
# Fix style
vendor/bin/php-cs-fixer fix

9 custom PHP-CS-Fixer implementations.

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
$config->registerCustomFixers([
new BlankLineAfterStatementFixer(),
new NumericLiteralSeparatorFixer(),
// ...
])
->setRules([
'RightCapital/blank_line_after_statement' => true,
'RightCapital/numeric_literal_separator' => true,
]);

Normalize composer.json files for consistent formatting.

  • Package list sorting
  • JSON structure validation
  • Dry-run and diff modes
  • Customizable indentation
Terminal window
# 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 1
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

Bridge between Composer events and Laravel event bus.

  • Composer lifecycle event handling
  • Laravel event dispatching
  • IDE helper integration
composer.json
{
"scripts": {
"post-autoload-dump": [
"@php artisan package:discover --ansi",
"RightCapital\\ComposerEventDispatcher\\ComposerEventDispatcher::handle"
]
}
}
  1. Composer triggers post-autoload-dump
  2. ComposerEventDispatcher::handle called
  3. Event converted to Laravel ComposerEvent
  4. Registered listeners respond (IDE helpers, etc.)

Automatic IDE helper file generation on Composer events.

  • Triggered by post-autoload-dump
  • Only runs in development
  • Generates autocomplete files
  • _ide_helper.php - Facade autocomplete
  • _ide_helper_models.php - Model property hints
  • .phpstorm.meta.php - PhpStorm metadata
Terminal window
composer require --dev rightcapital/ide-helper-files-generator

No additional configuration needed - auto-discovered via service provider.

  • barryvdh/laravel-ide-helper
  • rightcapital/composer-event-dispatcher

Synchronize environment variables between .env.local and .env.

  • Smart merge with conflict detection
  • Interactive and non-interactive modes
  • Missing key detection
  • Value comparison
Terminal window
# Interactive mode
php vendor/bin/env-sync
# Non-interactive (CI/CD)
php vendor/bin/env-sync --no-interaction
Scenario Action
Missing .env Copy .env.local
Missing keys Append from .env.local
Conflicting values Prompt user (interactive)
Identical values No action
Found conflicting values:
APP_DEBUG:
.env: false
.env.local: true
Update .env with .env.local value? [Y/n]:

# PHPStan
phpstan:
script:
- vendor/bin/phpstan analyse --ansi
# Rector
rector:
script:
- vendor/bin/rector process --dry-run
# PHP-CS-Fixer
php cs fixer:
script:
- vendor/bin/php-cs-fixer fix --dry-run --diff
# Composer Normalize
composer normalize:
script:
- ./libs/composer-normalize/bin/composer-normalize normalize --dry-run -n
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