定制 phpstan/phpstan-deprecation-rules 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

phpstan/phpstan-deprecation-rules

最新稳定版本:2.0.3

Composer 安装命令:

composer require phpstan/phpstan-deprecation-rules

包简介

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

README 文档

README

Build Latest Stable Version License

Installation

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:

includes:
    - 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 deprecation markers

You can implement extensions to support even e.g. custom #[MyDeprecated] attribute. Learn more.

Custom deprecated scopes

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

/** @deprecated */
function doFoo(): void
{
    // not reported:
    anotherDeprecatedFunction();
}

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:

services:
	-
		class: GroupLegacyScopeResolver
		tags:
			- phpstan.deprecations.deprecatedScopeResolver

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

统计信息

  • 总下载量: 71.65M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 437
  • 点击次数: 1
  • 依赖项目数: 6096
  • 推荐数: 7

GitHub 信息

  • Stars: 432
  • Watchers: 4
  • Forks: 20
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04