• Stars
    star
    360
  • Rank 118,230 (Top 3 %)
  • Language
    PHP
  • Created over 6 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

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 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.

More Repositories

1

phpstan

PHP Static Analysis Tool - discover bugs in your code without running it!
PHP
12,763
star
2

phpdoc-parser

Next-gen phpDoc parser with support for intersection types and generics
PHP
1,303
star
3

phpstan-symfony

Symfony extension for PHPStan
PHP
691
star
4

phpstan-strict-rules

Extra strict and opinionated rules for PHPStan
PHP
586
star
5

phpstan-doctrine

Doctrine extensions for PHPStan
PHP
577
star
6

phpstan-phpunit

PHPUnit extensions and rules for PHPStan
PHP
450
star
7

extension-installer

Composer plugin for automatic installation of PHPStan extensions.
PHP
395
star
8

phpstan-src

PHPStan's source code. This is where development happens. Check https://github.com/phpstan/phpstan for the distribution repository.
PHP
307
star
9

phpstan-webmozart-assert

PHPStan extension for webmozart/assert
PHP
160
star
10

phpstan-nette

Nette Framework class reflection extension for PHPStan & framework-specific rules
PHP
100
star
11

phpstan-shim

[DEPRECATED] This repository provides easy way to install PHPStan without the risk of conflicting dependencies.
PHP
87
star
12

phpstan-mockery

PHPStan extension for Mockery
PHP
81
star
13

phpstan-beberlei-assert

PHPStan extension for beberlei/assert
PHP
38
star
14

vim-phpstan

A Vim plugin for PHPStan - https://github.com/phpstan/phpstan. It calls `phpstan` to do static analysis of your PHP code and displays the errors in Vim's quickfix list.
PHP
29
star
15

php-8-stubs

PHP
27
star
16

phpstan-php-parser

PHP-Parser extension for PHPStan
Makefile
23
star
17

phpstan-dibi

Dibi class reflection extension for PHPStan
PHP
15
star
18

build-cs

Coding standard for 1st party PHPStan extensions
2
star