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.neon config:
parameters:
errorFormat: ticketswap
parameters:
editorUrl: 'vscode://file/%%file%%:%%line%%' # VS Code
# OR
editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%' # PhpStorm
Run PHPStan with the new formatter:
./vendor/bin/phpstan analyse
Expected Output:
string, App\Models\User) and variables for quick visual parsing.Daily Static Analysis
- name: Run PHPStan
run: ./vendor/bin/phpstan analyse --error-format=ticketswap
IDE-Specific Optimizations
vscode://file/%%file%%:%%line%% for direct file/line jumps.phpstorm://open?file=%%file%%&line=%%line%% for seamless navigation.Team Onboarding
.phpstan.neon template to your project’s templates/ folder to enforce consistent formatting across new developers.includes:
- vendor/ticketswap/phpstan-error-formatter/extension.neon
parameters:
errorFormat: ticketswap
editorUrl: 'vscode://file/%%file%%:%%line%%'
CI/CD Pipeline
./vendor/bin/phpstan analyse --error-format=ticketswap --level=8 --no-progress
--generate-baseline to baseline errors without cluttering logs.Custom PHPStan Rulesets
phpstan-rules) while keeping output readable:
includes:
- vendor/ticketswap/phpstan-error-formatter/extension.neon
- rulesets/custom-rules.neon
parameters:
errorFormat: ticketswap
Artisan Integration: Add a custom Artisan command to run PHPStan with the formatter:
// app/Console/Commands/RunPhpStan.php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class RunPhpStan extends Command
{
protected $signature = 'phpstan:analyse';
protected $description = 'Run PHPStan with the TicketSwap formatter';
public function handle()
{
$this->call('vendor:publish', ['--tag' => 'phpstan-config']);
$this->call('phpstan', [
'analyse',
'--error-format=ticketswap',
'--level=8',
]);
}
}
Register it in app/Console/Kernel.php:
protected $commands = [
Commands\RunPhpStan::class,
];
Laravel Forge/Envoyer: Configure your deploy script to run PHPStan with the formatter:
./vendor/bin/phpstan analyse --error-format=ticketswap --memory-limit=1G
Terminal/IDE Compatibility
cmd or older IDEs).file:/// URLs as a fallback (default behavior). Test with:
echo -e "\e]8;;file:///path/to/file.php\aClick here\e]8;;\a"
file:/// paths explicitly:
parameters:
editorUrl: 'file://%%file%%'
Path Truncation
/var/www/project/src/...) are truncated visually but remain clickable.truncatePaths: false in extension.neon (if supported in future versions).Highlighting Edge Cases
array<int, string>, mixed) may not be highlighted.CI/CD Output Parsing
--no-progress and --no-interaction flags to ensure clean output:
./vendor/bin/phpstan analyse --error-format=ticketswap --no-progress
PHPStan Level 10+
10) may produce overly verbose errors.--memory-limit and --parallel for better performance:
./vendor/bin/phpstan analyse --level=10 --error-format=ticketswap --parallel --memory-limit=2G
Verify Formatter is Active
Run PHPStan with --debug to confirm the formatter is loaded:
./vendor/bin/phpstan analyse --debug
Look for Using error formatter: ticketswap.
Check Editor URL Support
Test your editorUrl configuration by running:
echo "file://$(pwd)/app/Models/User.php" | xargs open # macOS
Or manually click the link in your terminal.
Customize Highlighting Extend the formatter by overriding its regex patterns. Example:
// In a custom extension.neon
services:
ticketswap.errorFormatter:
class: TicketSwap\ErrorFormatter\TicketSwapErrorFormatter
arguments:
- '%parameters.errorFormat%'
- '%parameters.editorUrl%'
- '%parameters.truncatePaths%' # Add custom config
Performance Tuning
--parallel and --memory-limit:
./vendor/bin/phpstan analyse --parallel --memory-limit=2G --error-format=ticketswap
excludeFiles:
- tests/**
- vendor/**
Custom Error Formatting
Extend TicketSwapErrorFormatter to add custom highlighting or post-processing:
namespace App\Services;
use TicketSwap\ErrorFormatter\TicketSwapErrorFormatter;
class CustomErrorFormatter extends TicketSwapErrorFormatter
{
protected function decorateMessage(string $message): string
{
$message = parent::decorateMessage($message);
// Add custom logic (e.g., colorize specific errors)
return str_replace('Deprecated', "\033[33mDeprecated\033[0m", $message);
}
}
Register it in extension.neon:
services:
ticketswap.errorFormatter:
class: App\Services\CustomErrorFormatter
Integrate with Laravel Logging Pipe PHPStan output to Laravel’s log channel for centralized error tracking:
./vendor/bin/phpstan analyse --error-format=ticketswap 2>&1 | php artisan log:read
Or create a custom command to log errors to the database.
Slack/Teams Notifications Use the formatter’s output to trigger notifications in Slack/Teams:
// In a custom Artisan command
$output = shell_exec('phpstan analyse --error-format=ticketswap --no-progress');
$this->sendSlackNotification($output);
How can I help you explore Laravel packages today?