Skip to content

Examples

Terminal window
# Quick check of your Laravel app
php artisan analyzer:analyze
# Analyze specific directories
php artisan analyzer:analyze app/Models app/Services
# With parallel processing
php artisan analyzer:analyze --parallel --workers=8
# Exclude vendor and storage directories
php artisan analyzer:analyze --exclude=vendor --exclude=storage

Generate XML prompts for automated fixing:

Terminal window
php artisan analyzer:analyze --agent

The output can be consumed by AI agents to automatically fix missing class references in parallel.

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 --parallel
analyze:
image: php:8.4-cli
script:
- composer install --no-dev --prefer-dist
- php artisan analyzer:analyze --parallel
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();
$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
]);

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());

Add to composer.json:

{
"scripts": {
"analyze": "php artisan analyzer:analyze --parallel",
"test": [
"@analyze",
"pest"
]
}
}

Run with:

Terminal window
composer analyze

Create .git/hooks/pre-commit:

#!/bin/bash
php artisan analyzer:analyze --parallel
if [ $? -ne 0 ]; then
echo "Analysis failed. Commit aborted."
exit 1
fi

Create environment-specific configs:

config/analyzer-dev.php
return AnalyzerConfig::make()
->paths(['app'])
->exclude(['vendor', 'storage'])
->workers(2);
// config/analyzer-ci.php
return AnalyzerConfig::make()
->paths(['app', 'tests'])
->workers(8)
->ignore(['Tests\\Fixtures\\*'])
->exclude(['vendor', 'node_modules', 'storage']);

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:

Terminal window
php artisan analyzer:analyze --route

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:

Terminal window
php artisan analyzer:analyze --lang
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'];
}
}