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
RuleEnforces
AssignVariableRuleVariables in snake_case
ParameterRuleParameters in snake_case
MethodRuleMethods in camelCase
ClassRuleClasses in StudlyCase
ClassConstRuleConstants in UPPER_CASE
PropertyRuleProperties in snake_case
PromotedPropertyRulePromoted properties in snake_case
DisallowModifyLocalStaticVariableRuleNo modifying local statics
RedundantVarAnnotationRuleNo redundant @var
DisallowCacheForeverExceptInMemoryCacheDriverRuleRestrict 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
RulePurpose
UseFullyQualifiedClassNameFacadeRectorConvert 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.

FixerPurpose
BlankLineAfterStatementFixerBlank lines after do/for/if/switch/while
BlankLineAfterTraitUsesFixerBlank line after trait imports
BlankLineAfterEnumCasesFixerBlank line after enum cases
NoMultipleConditionalExpressionsPerLineFixerOne condition per line
NoSpaceAfterCommaInPhpdocArrayFixerNo spaces in PHPDoc arrays
SpaceBeforeSingleLineCommentFixerSpace before inline comments
UseFullyQualifiedClassNameInPhpdocFixerFQCNs in PHPDoc
NumericLiteralSeparatorFixerUnderscores in numbers (1_000_000)
ReadonlyAfterVisibilityInConstructorPromotionFixerpublic 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
OptionPurpose
--diffShow changes
--dry-runPreview only
--indent-size NIndent size
--indent-style space|tabIndent style
--no-update-lockSkip 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
ScenarioAction
Missing .envCopy .env.local
Missing keysAppend from .env.local
Conflicting valuesPrompt user (interactive)
Identical valuesNo 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
PackageTypePurpose
phpstan-rulesStatic analysisType checking, naming conventions
rector-rulesRefactoringPHP version upgrades, code cleanup
php-cs-fixer-rulesCode styleFormatting configuration
php-cs-fixer-custom-fixersCode style9 custom fixers
composer-normalizeToolingcomposer.json formatting
composer-event-dispatcherBridgeComposer-Laravel event bridge
ide-helper-files-generatorDevelopmentIDE autocomplete
env-syncUtilityEnvironment sync