Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Phpstan Deprecation Rules Laravel Package

phpstan/phpstan-deprecation-rules

View on GitHub
Deep Wiki
Context7

Getting Started

Install the package via Composer as a development dependency:

composer require --dev phpstan/phpstan-deprecation-rules

If you use phpstan/extension-installer, the rules are auto-configured. Otherwise, manually include vendor/phpstan/phpstan-deprecation-rules/rules.neon in your PHPStan config (phpstan.neon). Run vendor/bin/phpstan analyse — the extension will now catch all usages of deprecated classes, methods, properties, constants, and traits annotated with @deprecated.

Implementation Patterns

  • Detect deprecations in third-party packages: Use PHPStan stub files to annotate @deprecated on external classes/methods (e.g., in stubs/). Place stubs in your repo and reference them via parameters.stubsDir in config.
  • Suppress false positives in legacy code: Wrap test code for deprecated APIs in @group legacy and implement a custom DeprecatedScopeResolver to exclude those scopes from warnings.
  • Custom deprecation markers: Define your own attributes (e.g., #[Deprecated(reason: '…')]) and implement a DeprecationRuleExtension to register custom deprecation detection.
  • Daily workflow: Run PHPStan in CI before merges to catch accidental use of deprecated symbols. Integrate deprecation warnings into your PR checks to enforce proactive migration.

Gotchas and Tips

  • Deprecation warnings are not reported in deprecated scopes (e.g., methods/functions marked @deprecated) — this prevents noise when maintaining legacy code.
  • Since v2.0+, several legacy rules were consolidated under *Restricted*Extension classes (e.g., RestrictedMethodUsageExtension), meaning method, property, and constant deprecations now share logic — ensure you’re using the latest version to benefit from fixes.
  • PHP version awareness: Deprecation reporting for constants respects Scope->getPhpVersion() — align your phpVersion setting in phpstan.neon with your target environment.
  • Avoid hard-to-debug false negatives: Stub files must be loaded before analysis — verify stubsDir is set and stubs include all relevant symbols (missing annotations won’t be caught).
  • Extensibility: The DeprecatedScopeResolver interface is your main extension point for custom logic — combine it with @group annotations, custom docblocks, or symfony/contracts-style #[Deprecated] to scale adoption.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport