PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.

Installs: 29 262 355

Dependents: 3 540

Suggesters: 6

Security: 0

Stars: 338

Watchers: 6

Forks: 17

Open Issues: 14


1.1.4 2023-08-05 09:02 UTC


Build Latest Stable Version License


To use this extension, require it in Composer:

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

If you also install phpstan/extension-installer then you're all set!

Manual installation

If you don't want to use phpstan/extension-installer, include rules.neon in your project's PHPStan config:

    - vendor/phpstan/phpstan-deprecation-rules/rules.neon

Deprecating code you don't own

This extension emits deprecation warnings on code, which uses properties/functions/methods/classes which are annotated as @deprecated.

In case you don't own the code which you want to be considered deprecated, use PHPStan Stub Files to declare deprecations for vendor files like:

/** @deprecated */
class ThirdPartyClass {}

Custom deprecated scopes

Usage of deprecated code is not reported in code that is also deprecated:

/** @deprecated */
function doFoo(): void
    // not reported:

If you have a different way of marking code that calls deprecated symbols on purpose and you don't want these calls to be reported either, you can write an extension by implementing the DeprecatedScopeResolver interface.

For example if you mark your PHPUnit tests that test deprecated code with @group legacy, you can implement the extension this way:

class GroupLegacyScopeResolver implements DeprecatedScopeResolver

	public function isScopeDeprecated(Scope $scope): bool
		$function = $scope->getFunction();
		return $function !== null
			&& $function->getDocComment() !== null
			&& strpos($function->getDocComment(), '@group legacy') !== false;


And register it in your configuration file:

		class: GroupLegacyScopeResolver
			- phpstan.deprecations.deprecatedScopeResolver

Learn more about Scope, a core concept for implementing custom PHPStan extensions.