Best Practices Analyzers
15 analyzers ensuring you follow Laravel ecosystem best practices and framework conventions.
Overview
Best Practices analyzers focus on Laravel-specific patterns, framework conventions, and architectural best practices. These analyzers help ensure your code follows Laravel's intended usage patterns and prevents common mistakes that can lead to maintainability issues or performance problems.
Key Analyzers
Laravel Conventions
Logic in Routes
Detects business logic in route files
Logic in Blade
Detects complex logic in Blade templates
Hardcoded Configuration
Detects configuration values outside config files
Eloquent & Database
Eloquent N+1 Query
Detects N+1 query problems
Missing Chunk
Detects missing chunk() calls for large datasets
Missing Database Transactions
Detects operations that should use database transactions
Mixed Query Builder and Eloquent
Detects inconsistent query building patterns
Code Organization
Fat Model
Detects models with too much business logic that violate Single Responsibility Principle
Service Container Resolution
Detects manual service container resolution and recommends constructor dependency injection
Error Handling & Logging
Silent Failure
Detects empty catch blocks and error suppression that hide failures
Missing Error Tracking
Ensures error tracking is configured
Anti-Patterns
Helper Function Abuse
Detects overuse of global helper functions
Hardcoded Storage Paths
Detects hardcoded file paths
PHP-Side Data Filtering
Detects filtering that should be done in database
Framework Override
Detects dangerous extensions of Laravel core classes that break during framework upgrades
How They Work
Best Practices analyzers use:
- Pattern Matching: Identifies Laravel-specific patterns and conventions
- AST Analysis: Analyzes code structure to detect architectural violations
- Query Analysis: Examines database queries for optimization opportunities
- Convention Validation: Checks code against Laravel best practices
Severity Levels
| Severity | Description | Examples |
|---|---|---|
| High | Issues that violate core Laravel principles | Logic in routes, N+1 queries, missing transactions |
| Medium | Issues that reduce maintainability | Fat models, hardcoded paths |
| Low | Best practice violations | Helper function abuse |
Running Best Practices Analyzers
Run All Best Practices Analyzers
php artisan shield:analyze --category=best-practicesRun Specific Analyzer
php artisan shield:analyze --analyzer=eloquent-n-plus-one
php artisan shield:analyze --analyzer=missing-database-transactions
php artisan shield:analyze --analyzer=fat-modelRun Multiple Analyzers
php artisan shield:analyze --analyzer=eloquent-n-plus-one,missing-database-transactions,chunk-missingBest Practices
Development
- Run best practices analyzers during code reviews
- Fix High severity issues before merging
- Use analyzers to learn Laravel conventions
Code Reviews
- Review best practices violations in pull requests
- Use violations as teaching opportunities
- Ensure new code follows Laravel patterns
Team Standards
- Agree on which best practices are mandatory
- Document team-specific conventions
- Use analyzers to maintain consistency across codebase
Related Categories
- Security Analyzers - Prevent security vulnerabilities
- Code Quality Analyzers - Maintain code quality standards
- Reliability Analyzers - Prevent runtime errors
- Performance Analyzers - Optimize application performance