2017 © Pedro Peláez
 

library phpstan-deprecation-rules

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

image

phpstan/phpstan-deprecation-rules

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

  • Saturday, June 30, 2018
  • by ondrejmirtes
  • Repository
  • 7 Watchers
  • 30 Stars
  • 4,155 Installations
  • PHP
  • 18 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

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

Build Latest Stable Version License, (*1)

Installation

To use this extension, require it in Composer:, (*2)

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

If you also install phpstan/extension-installer then you're all set!, (*3)

Manual installation
, (*4)

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

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

, (*6)

Deprecating code you don't own

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

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:, (*8)

/** @deprecated */
class ThirdPartyClass {}

Custom deprecated scopes

Usage of deprecated code is not reported in code that is also deprecated:, (*9)

/** @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., (*10)

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

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:, (*12)

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

Learn more about Scope, a core concept for implementing custom PHPStan extensions., (*13)

The Versions