Examples
Basic Laravel Usage
Section titled “Basic Laravel Usage”Artisan Command
Section titled “Artisan Command”# Quick check of your Laravel appphp artisan analyzer:analyze
# Analyze specific directoriesphp artisan analyzer:analyze app/Models app/Services
# With parallel processingphp artisan analyzer:analyze --parallel --workers=8
# Exclude vendor and storage directoriesphp artisan analyzer:analyze --exclude=vendor --exclude=storageAI Agent Mode
Section titled “AI Agent Mode”Generate XML prompts for automated fixing:
php artisan analyzer:analyze --agentThe output can be consumed by AI agents to automatically fix missing class references in parallel.
CI/CD Integration
Section titled “CI/CD Integration”GitHub Actions
Section titled “GitHub Actions”name: Code Analysis
on: [push, pull_request]
jobs: analyze: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: shivammathur/setup-php@v2 with: php-version: '8.4' - run: composer install --no-dev --prefer-dist - run: php artisan analyzer:analyze --parallelGitLab CI
Section titled “GitLab CI”analyze: image: php:8.4-cli script: - composer install --no-dev --prefer-dist - php artisan analyzer:analyze --parallelProgrammatic Laravel Integration
Section titled “Programmatic Laravel Integration”use Cline\Analyzer\Analyzer;use Cline\Analyzer\Config\AnalyzerConfig;
$config = AnalyzerConfig::make() ->paths([ app_path(), base_path('tests'), ]) ->ignore([ 'Illuminate\\*', 'Laravel\\*', ]) ->exclude([ 'vendor', 'storage', ]) ->workers(4);
$analyzer = new Analyzer($config);$results = $analyzer->analyze();Custom Ignore and Exclude Patterns
Section titled “Custom Ignore and Exclude Patterns”$config = AnalyzerConfig::make() ->paths(['src']) ->ignore([ 'Illuminate\\*', // Laravel framework 'Symfony\\Component\\*', // Symfony components 'PHPUnit\\*', // PHPUnit framework 'Mockery\\*', // Mockery mocking 'App\\Generated\\*', // Generated code ]) ->exclude([ 'vendor', // Skip vendor directory 'node_modules', // Skip node_modules 'storage', // Skip storage directory 'build', // Skip build artifacts '*.blade.php', // Skip Blade templates 'tests/fixtures/*', // Skip test fixtures ]);JSON Output Reporter
Section titled “JSON Output Reporter”Create a custom JSON reporter:
use Cline\Analyzer\Contracts\ReporterInterface;use Cline\Analyzer\Data\AnalysisResult;
class JsonFileReporter implements ReporterInterface{ private array $data = [];
public function start(array $files): void { $this->data = ['files' => count($files), 'results' => []]; }
public function progress(AnalysisResult $result): void { $this->data['results'][] = [ 'file' => $result->file->getPathname(), 'success' => $result->success, 'missing' => $result->missing, ]; }
public function finish(array $results): void { file_put_contents( 'analysis-report.json', json_encode($this->data, JSON_PRETTY_PRINT) ); }}
$config->reporter(new JsonFileReporter());Composer Script
Section titled “Composer Script”Add to composer.json:
{ "scripts": { "analyze": "php artisan analyzer:analyze --parallel", "test": [ "@analyze", "pest" ] }}Run with:
composer analyzePre-commit Hook
Section titled “Pre-commit Hook”Create .git/hooks/pre-commit:
#!/bin/bashphp artisan analyzer:analyze --parallelif [ $? -ne 0 ]; then echo "Analysis failed. Commit aborted." exit 1fiMultiple Configurations
Section titled “Multiple Configurations”Create environment-specific configs:
return AnalyzerConfig::make() ->paths(['app']) ->exclude(['vendor', 'storage']) ->workers(2);
// config/analyzer-ci.phpreturn AnalyzerConfig::make() ->paths(['app', 'tests']) ->workers(8) ->ignore(['Tests\\Fixtures\\*']) ->exclude(['vendor', 'node_modules', 'storage']);Route Analysis
Section titled “Route Analysis”Validate route names in your Laravel application:
use Cline\Analyzer\Analyzer;use Cline\Analyzer\Config\AnalyzerConfig;use Cline\Analyzer\Resolvers\RouteAnalysisResolver;
$routeResolver = new RouteAnalysisResolver( routesPath: base_path('routes'), cacheRoutes: true, cacheTtl: 3600, reportDynamic: true, includePatterns: ['admin.*', 'api.*'], ignorePatterns: ['debug.*'], app: app());
$config = AnalyzerConfig::make() ->paths(['app', 'resources/views']) ->analysisResolver($routeResolver);
$analyzer = new Analyzer($config);$results = $analyzer->analyze();Or via command:
php artisan analyzer:analyze --routeTranslation Analysis
Section titled “Translation Analysis”Validate translation keys in your Laravel application:
use Cline\Analyzer\Analyzer;use Cline\Analyzer\Config\AnalyzerConfig;use Cline\Analyzer\Resolvers\TranslationAnalysisResolver;
$translationResolver = new TranslationAnalysisResolver( langPath: base_path('lang'), locales: ['en', 'es', 'fr'], reportDynamic: true, vendorPath: base_path('vendor/*/lang'), ignore: ['debug.*', 'temp.*'], includePatterns: ['validation.*', 'auth.*']);
$config = AnalyzerConfig::make() ->paths(['app', 'resources/views']) ->analysisResolver($translationResolver);
$analyzer = new Analyzer($config);$results = $analyzer->analyze();Or via command:
php artisan analyzer:analyze --langProgrammatic API
Section titled “Programmatic API”use Cline\Analyzer\Analyzer;use Cline\Analyzer\Config\AnalyzerConfig;
class MyAnalyzer{ public function run(): bool { $config = AnalyzerConfig::make() ->paths($this->getPaths()) ->ignore($this->getIgnorePatterns()) ->exclude($this->getExcludePatterns());
$analyzer = new Analyzer($config); $results = $analyzer->analyze();
return !$analyzer->hasFailures($results); }
private function getPaths(): array { return ['src', 'app']; }
private function getIgnorePatterns(): array { return ['Vendor\\*']; }
private function getExcludePatterns(): array { return ['vendor', 'storage', 'cache']; }}