• Stars
    star
    341
  • Rank 119,380 (Top 3 %)
  • Language
    PHP
  • Created almost 6 years ago
  • Updated 2 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,445
star
2

phpdoc-parser

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

phpstan-symfony

Symfony extension for PHPStan
PHP
655
star
4

phpstan-doctrine

Doctrine extensions for PHPStan
PHP
547
star
5

phpstan-strict-rules

Extra strict and opinionated rules for PHPStan
PHP
545
star
6

phpstan-phpunit

PHPUnit extensions and rules for PHPStan
PHP
427
star
7

extension-installer

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

phpstan-src

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

phpstan-webmozart-assert

PHPStan extension for webmozart/assert
PHP
150
star
10

phpstan-nette

Nette Framework class reflection extension for PHPStan & framework-specific rules
PHP
98
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
76
star
13

phpstan-beberlei-assert

PHPStan extension for beberlei/assert
PHP
35
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
28
star
15

php-8-stubs

PHP
25
star
16

phpstan-php-parser

PHP-Parser extension for PHPStan
Makefile
23
star
17

phpstan-dibi

Dibi class reflection extension for PHPStan
PHP
13
star
18

build-cs

Coding standard for 1st party PHPStan extensions
2
star