mayflower/php-codebrowser
Static PHP code browser that generates a cross-referenced HTML view of your source tree. Jump to classes, methods, and references, inspect files with syntax highlighting, and ship browsable documentation for audits, reviews, or onboarding.
Installation
composer require mayflower/php-codebrowser
Add the service provider to config/app.php:
Mayflower\CodeBrowser\CodeBrowserServiceProvider::class,
Basic Usage Generate a code browser for a single file:
use Mayflower\CodeBrowser\CodeBrowser;
$browser = new CodeBrowser();
$browser->addFile('/path/to/YourClass.php');
$browser->generate();
Outputs to ./codebrowser/output/ by default.
First Use Case Quickly visualize a single class with:
$browser->addFile(app_path('Http/Controllers/YourController.php'))
->withQATools(['phpstan', 'phpmd'])
->generate();
Bulk Processing
Recursively scan a directory (e.g., app/):
$browser->addDirectory(app_path())
->exclude('tests', 'vendor')
->generate();
QA Tool Integration
Enable tools via config (config/codebrowser.php):
'tools' => [
'phpstan' => true,
'phpmd' => ['ruleset' => 'cleancode'],
'phpcs' => ['standard' => 'PSR12'],
],
Or programmatically:
$browser->withQATools(['phpstan', 'phpmd']);
Custom Output Override output path:
$browser->setOutputPath(storage_path('codebrowser'));
Or use a custom renderer:
$browser->setRenderer(new Mayflower\CodeBrowser\Renderers\JsonRenderer());
CI/CD Integration Cache results for faster builds:
$browser->cacheResults(3600); // Cache for 1 hour
Laravel Artisan Command Create a custom command:
use Mayflower\CodeBrowser\CodeBrowser;
class CodeBrowserCommand extends Command {
protected $signature = 'codebrowser:generate {--path= : Path to analyze}';
public function handle() {
$browser = new CodeBrowser();
$browser->addDirectory($this->option('path') ?? app_path());
$browser->generate();
$this->info('Code browser generated!');
}
}
Event Listeners
Trigger on codebrowser.generated event:
event(new CodeBrowserGenerated($browser->getResults()));
Dynamic Tool Configuration Use environment variables:
$browser->withQATools(
array_filter(['phpstan', 'phpmd'], fn($tool) => env("CODEBROWSER_{$tool}", true))
);
Tool Dependencies
phpstan, phpmd) are installed globally or via Composer.composer show mayflower/php-codebrowser
Performance
--parallel flag (if supported in future versions) or chunk directories:
$browser->addDirectory(app_path('Http/Controllers'))
->addDirectory(app_path('Models'));
Path Handling
$browser->addFile(realpath(app_path('YourFile.php')));
QA Tool Conflicts
phpstan and phpmd analyzing the same file twice).php artisan codebrowser:clear-cache
Verbose Output Enable debug mode:
$browser->setDebug(true);
Or via config:
'debug' => env('APP_DEBUG', false),
Log Analysis
Check storage/logs/codebrowser.log for tool-specific errors.
Tool-Specific Quirks
phpstan.neon is configured for your project.$browser->withQATools(['phpmd' => ['ruleset' => 'custom-ruleset.xml']]);
Custom QA Tools
Implement Mayflower\CodeBrowser\Contracts\QATool:
class CustomTool implements QATool {
public function analyze(File $file): array {
return ['issues' => $this->runCustomAnalysis($file)];
}
}
Register via service provider:
$this->app->bind(QATool::class, function() {
return collect([new CustomTool()]);
});
Renderer Extensions
Extend Mayflower\CodeBrowser\Renderers\BaseRenderer to add custom output formats (e.g., Markdown, HTML tables).
Pre/Post-Processing Use events to modify results:
CodeBrowser::generated(function ($results) {
$results->each(fn($file) => $file->addCustomAnnotation('MyAnnotation'));
});
Configuration Overrides Dynamically override tool settings:
$browser->overrideToolConfig('phpstan', ['level' => 'max']);
How can I help you explore Laravel packages today?