ticketswap/phpstan-error-formatter
Minimalistic PHPStan error formatter with clickable file+line links per error, no wrapping output, naive syntax highlighting, and visually truncated paths while preserving links. Easy install via Composer; enable with errorFormat: ticketswap.
composer require --dev ticketswap/phpstan-error-formatter
phpstan/extension-installer (recommended) or manually include extension.neon in your PHPStan config:
includes:
- vendor/ticketswap/phpstan-error-formatter/extension.neon
phpstan.neon:
parameters:
errorFormat: ticketswap
editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%' # or 'vscode://file/%%file%%:%%line%%'
Run PHPStan with your existing configuration:
./vendor/bin/phpstan analyse
[ERROR] Class App\Models\User has no property $nonExistentProperty
src/App/Models/User.php:15:10
Daily Static Analysis
- name: Run PHPStan
run: ./vendor/bin/phpstan analyse --error-format=ticketswap
Editor/IDE-Specific Configurations
phpstorm://open?file=%%file%%&line=%%line%% for seamless navigation.vscode://file/%%file%%:%%line%% for direct line jumps.Team Onboarding
CONTRIBUTING.md or DEVELOPMENT.md to ensure consistency.## PHPStan Errors
Run `phpstan analyse` for static analysis. Errors include clickable file/line links:
- **PhpStorm**: Click the link to open the file.
- **VS Code**: Click to jump to the line.
- **Terminal**: Copy-paste the path/line into your editor.
Custom PHPStan Rulesets
level: 8) for maximum benefit:
includes:
- vendor/ticketswap/phpstan-error-formatter/extension.neon
level: 8
parameters:
errorFormat: ticketswap
Automated Cleanup of Redundant Docblocks
@param docblocks for native types (e.g., string, int), reducing noise in AI-generated or legacy code.Artisan Command Integration
phpstan:analyze command (if using laravel-pint or similar) to enforce the formatter:
// app/Console/Commands/AnalyzeCode.php
protected function runPhpStan()
{
$command = 'phpstan analyse --error-format=ticketswap';
$this->callSilently('vendor:publish', ['--provider' => 'Laravel\Pint\PintServiceProvider']);
$this->call('cache:clear');
$this->line($this->runCommand($command));
}
Forge/Envoyer Deployments
# In your Envoyer recipe or Forge deploy script
composer install --no-dev
composer require --dev ticketswap/phpstan-error-formatter
./vendor/bin/phpstan analyse --error-format=ticketswap
Laravel IDE Helper Integration
barryvdh/laravel-ide-helper, run PHPStan before generating helpers to catch issues early:
./vendor/bin/phpstan analyse --error-format=ticketswap
./vendor/bin/php artisan ide-helper:generate
Terminal/IDE Compatibility
file:/// URLs as a fallback (configured via editorUrl):
parameters:
editorUrl: 'file://%%file%%'
Path Truncation in AI Environments
/Volumes/CS/www/src/...) may break clickable links if truncated.Line Number 0 Edge Case
line: 0 (e.g., from phpstan:no-extra-args) may display incorrectly.0 (since PR 31). No configuration needed.Custom Type Highlighting Limitations
Class::Constant or stdClass).Stringable, PR 24 for stdClass). Update regularly:
composer update ticketswap/phpstan-error-formatter
Windows Path Handling
C:\project\src\...) may not work with file:// URLs.vscode://file/ or phpstorm://open?file= with forward slashes (the formatter handles this automatically).Verify Formatter Activation
--verbose to confirm the formatter is loaded:
./vendor/bin/phpstan analyse --verbose
[PHPStan\Analyser\Error] Using error formatter: ticketswap
Check editorUrl Configuration
editorUrl:
phpstorm://open?file=%%file%%&line=%%line%%vscode://file/%%file%%:%%line%%file://%%file%% (may require opening in browser).Override Formatter Temporarily
./vendor/bin/phpstan analyse --error-format=default
Handle False Positives
extension.neon:
services:
TicketSwap\PhpStanErrorFormatter\TicketSwapErrorFormatter:
decorate: true
decorateWith: @phpstan.errorFormatter
parameters:
customTypes:
- 'My\\Custom\\Type'
Custom Highlighting Rules
TicketSwapErrorFormatter:
// app/Providers/AppServiceProvider.php
use TicketSwap\PhpStanErrorFormatter\TicketSwapErrorFormatter;
public function register()
{
$this->app->bind(TicketSwapErrorFormatter::class, function ($app) {
$formatter = new TicketSwapErrorFormatter();
$formatter->addCustomType('My\\Custom\\Type');
return $formatter;
});
}
Modify Error Output
formatErrors() method to add pre/post-processing:
class CustomErrorFormatter extends TicketSwapErrorFormatter
{
public function formatErrors(array $errors): string
{
$output = parent::formatErrors($errors);
return "[CUSTOM] $output"; // Prefix all errors
}
}
extension.neon:
services:
CustomErrorFormatter:
class: App\Services\CustomErrorFormatter
decorate: true
decorateWith: @phpstan.errorFormatter
Integrate with Laravel Logging
// In your PHPStan command or service
How can I help you explore Laravel packages today?