rollerscapes/standards
A standardized set of PHP code style and quality assurance rules from Rollerscapes, bundling the tooling and configuration used across all its projects, including Rollerworks, HuPKit, and Rollersearch, to keep coding standards consistent and enforce quality checks.
Installation Add the package to your Laravel project:
composer require rollerscapes/standards --dev
This installs PHP-CS-Fixer, PHPStan (with Symfony/Laravel extensions), and PHPUnit configurations.
First Command Run the integrated linter and static analyzer:
php artisan standards:check
This executes both PHP-CS-Fixer (auto-fixable) and PHPStan (static analysis) in a single pass.
Where to Look First
config/standards.php (auto-generated on first run) for customizable rules (PHP-CS-Fixer, PHPStan levels, excluded paths).make lint # Runs PHP-CS-Fixer
make stan # Runs PHPStan
make test # Runs PHPUnit with internal test checks
php artisan standards:git-hook
Daily Development Workflow
php artisan standards:fix
Applies PHP-CS-Fixer rules (e.g., PSR-12 compliance, PHPDoc alignment) to staged files.php artisan standards:analyze --level=5
Runs PHPStan with a custom strictness level (default: max).php artisan standards:check app/Http/Controllers
Targets specific directories (e.g., controllers, services).CI/CD Pipeline Integration
# GitHub Actions example
- name: Enforce Standards
run: php artisan standards:check --fail-on-errors
php artisan standards:analyze --generate-baseline
Generates a baseline file (phpstan.baseline.neon) to ignore known issues temporarily.Customization
config/standards.php:
php artisan vendor:publish --provider="Rollerscapes\Standards\StandardsServiceProvider" --tag="config"
Example: Adjust PHPStan’s level or exclude Laravel-specific false positives:
'phpstan' => [
'level' => 7, // Lower strictness for legacy code
'exclude_paths' => [
'app/Providers/AppServiceProvider.php', // Skip problematic files
],
],
phpstan.neon:
includes:
- vendor/rollerscapes/standards/phpstan.neon
- phpstan.neon # Your custom rules
Laravel-Specific Patterns
php artisan standards:analyze --include-tests --include-blade
phpstan/phpstan-doctrine for Doctrine/Laravel Eloquent checks (included by default).Team Collaboration
php artisan standards:init
Sets up the package, config, and Git hooks in one command.phpstan.baseline.neon to the repo to track known issues across contributors.With Laravel Pint
Replace or supplement Pint by configuring PHP-CS-Fixer in config/standards.php:
'php-cs-fixer' => [
'rules' => [
'@PSR12' => true,
'no_unused_imports' => true, // Add Laravel-specific rules
],
],
Run via:
php artisan standards:fix
With Laravel Forge/Envoyer Add a deploy hook to run standards checks:
php artisan standards:check --fail-on-errors
With PHPUnit
The package enforces internal test marking (e.g., @internal annotations). Update tests:
/**
* @internal
*/
class ExampleTest extends TestCase { ... }
With IDE Support
Configure PHPStan in your IDE (e.g., PHPStorm) to use the project’s phpstan.neon for real-time feedback.
PHPStan Strictness
level=max may break legacy Laravel code (e.g., dynamic properties, loose typing).level=5 and incrementally increase strictness:
php artisan standards:analyze --level=5
Laravel-Specific False Positives
config/standards.php:
'phpstan' => [
'exclude_paths' => [
'app/Providers/*',
'routes/*',
],
],
ignoreErrors in phpstan.neon:
parameters:
ignoreErrors:
- '#Method Illuminate\\\\Foundation\\\\Application::bind should not be private#'
PHP-CS-Fixer Conflicts
php artisan vendor:publish --tag=php-cs-fixer
Then edit .php-cs-fixer.dist.php to prioritize project-specific rules.Performance Overhead
level=max can slow down CI/CD pipelines for large codebases.--generate-baseline.php artisan standards:analyze --parallel
Git Hooks
--allow-runtime-errors for non-critical checks:
php artisan standards:git-hook --allow-runtime-errors
Verbose Output
Run with -v for detailed logs:
php artisan standards:check -v
Isolate Issues Target specific files or directories:
php artisan standards:analyze app/Http/Controllers/UserController.php
PHPStan Error Codes Look up errors in the PHPStan documentation or use:
php artisan standards:analyze --error-format=github
Configuration Validation
Validate your config/standards.php:
php artisan standards:validate-config
Custom PHPStan Rules Add project-specific rules by extending the config:
# phpstan.neon
includes:
- vendor/rollerscapes/standards/phpstan.neon
- rules/custom.neon # Your custom rules
Dynamic Rules
Use PHPStan’s parameters to conditionally enable rules:
parameters:
level: 7
checkMissingIterableValueType: true
Hooks and Events Extend the package’s Artisan commands by binding to its events (if supported). Example:
// app/Providers/StandardsServiceProvider.php
public function boot()
{
Standards::extend(function ($command) {
$command->listen('before-check', function () {
// Pre-check logic (e.g., log start time)
});
});
}
Forking the Package If Rollerscapes stops maintaining the package, fork it and:
Makefile to include Laravel-specific tasks.PHP Version Mismatch
composer.json:
"require-dev": {
"phpstan/phpstan": "1.10.0" // PHP 8.0 compatible
}
**Doct
How can I help you explore Laravel packages today?