spaze/phpstan-disallowed-calls
PHPStan extension to define and enforce a denylist of disallowed function and method calls in your codebase. Catch legacy, unsafe, or unwanted APIs during static analysis with configurable rules and helpful error messages.
neon/php config) and non-intrusive, making them ideal for enforcing coding standards, security policies, or legacy migration constraints in Laravel applications.Request::oldInput() → Request::old()).DB::select()) in favor of Eloquent.new for bound dependencies).phpstan/extension-installer). This package adds no new runtime overhead.App\Services\*) or files, allowing granular control.str_replace() globally might break legacy code.@allow-disallowed-call annotations)?phpstan/extension-installer (auto-loads rules).phpstan/phpstan (core static analysis).phpstan/phpstan-laravel (Laravel-specific rules).laravel-pint for consistent code formatting alongside rule enforcement.roave/security-advisories to block vulnerable dependencies.rector/rector for automated refactoring of disallowed calls.new for service container bindings).--level=max in PHPStan to identify existing violations.@allow-disallowed-call sparingly for legacy code.Request::oldInput() → Request::old()).phpstan.neon with clear comments:
includes:
- vendor/spaze/phpstan-disallowed-calls/extension.neon
disallowedCalls:
'Illuminate\Support\Facades\DB::select':
message: 'Use Eloquent queries instead.'
^1.10.0). Check the package’s upgrade notes if available.Illuminate\*). Ensure rules align with your Laravel version’s APIs.Carbon::parse() in favor of Carbon::createFromFormat()).composer require --dev spaze/phpstan-disallowed-calls.@allow-disallowed-call) in a RULES.md file.@allow-disallowed-call use cases.// Allowed in tests only
#[\Spaze\DisallowedCalls\AllowedInTests]
public function testDeprecatedMethod() { ... }
--error-format=github for actionable PR feedback.- name: PHPStan
run: vendor/bin/phpstan analyse --level=max
phpstan --generate-baseline).phpstan --parallel.path: or namespace: filters to limit rule application to critical paths (e.g., App\*).disallowedCalls:
'App\Services\*':
'Symfony\Component\HttpFoundation\Request::getClientIp':
message: 'Use $request->ip() instead.'
@allow-disallowed-call for edge cases.DB::select() calls in 2 weeks").How can I help you explore Laravel packages today?