wpdesk/phpstan-rules

Meta package with PHPStan configuration for WP Desk projects

Installs: 887

Dependents: 7

Suggesters: 0

Security: 0

Type:phpstan-extension

1.1.0 2023-11-20 08:10 UTC

This package is auto-updated.

Last update: 2024-04-20 08:56:15 UTC


README

This meta-package contains PHPStan configuration for WP Desk projects. This includes dependent extensions like szepeviktor/phpstan-wordpress, and additional, default configuration like inclusion of WooCommerce stubs.

Installation

composer require wpdesk/phpstan-rules

Usage

After installation, you can simply use PHPStan in your project without the need to further configuration. Nevertheless, as project grows, it's worth to add even the basic one.

To run PHPStan, simply execute the following command (<path> is only required if not present in configuration file):

vendor/bin/phpstan analyse <path>

Dependencies between plugins

Besides WordPress and WooCommerce, it may be sometimes necessary to analyse dependencies between plugins, e.g. when developing an extension to base plugin, PHPStan needs to be aware of the dependent plugin's codebase.

In such cases it is necessary to generate the stubs for the dependent plugin with the use of stub generator library. Try to install it as system-wide utility, rather than plugin's package.

composer global require php-stubs/generator

With the aid of this library, you will be able to provide read-only access to the dependent codebase for PHPStan purposes. Use stub extension to ignore this file by your editor analyzers.

generate-stubs --out=/path/to/.stubs/dependency.stub -- /path/to/dependency/src

Remember to regenerate the stubs, whenever there's an important change in upstream plugin.

Finally, include generated stubs in your PHPStan configuration.

parameters:
  scanFiles:
    - .stubs/dependency.stub