Download the PHP package mglaman/phpstan-drupal without Composer
On this page you can find all versions of the php package mglaman/phpstan-drupal. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mglaman/phpstan-drupal
More information about mglaman/phpstan-drupal
Files in mglaman/phpstan-drupal
Package phpstan-drupal
Short Description Drupal extension and rules for PHPStan
License MIT
Informations about the package phpstan-drupal
phpstan-drupal
Extension for PHPStan to allow analysis of Drupal code.
PHPStan is able to discover symbols by using autoloading provided by Composer. However, Drupal does not provide autoloading information for modules and themes. This project registers those namespaces so that PHPStan can properly discover symbols in your Drupal code base automatically.
Sponsors
Usage
When you are using phpstan/extension-installer
, phpstan.neon
will be automatically included.
Manual installation
If you don't want to use `phpstan/extension-installer`, include `extension.neon` in your project's PHPStan config: To include Drupal specific analysis rules, include this file:Getting help
Ask for assistance in the discussions or #phpstan channel on Drupal Slack.
Excluding tests from analysis
To exclude tests from analysis, add the following parameter
Deprecation testing
This project depends on phpstan/phpstan-deprecation-rules
which adds deprecation rules. We provide Drupal-specific
deprecated scope resolvers.
To only handle deprecation testing, use a phpstan.neon
like this:
To disable deprecation rules while using phpstan/extension-installer
, you can do the following:
See the extension-installer
documentation for more information: https://github.com/phpstan/extension-installer#ignoring-a-particular-extension
Adapting to your project
Customizing rules
Disabling checks for extending @internal
classes
You can disable the ClassExtendsInternalClassRule
rule by adding the following to your phpstan.neon
:
Entity storage mappings.
The EntityTypeManagerGetStorageDynamicReturnTypeExtension
service helps map dynamic return types. This inspects the
passed entity type ID and tries to return a known storage class, besides the default EntityStorageInterface
. The
default mapping can be found in extension.neon
. For example:
To add support for custom entities, you may add the same definition in your project's phpstan.neon
. See the following
example for adding a mapping for Search API:
Similarly, the EntityStorageDynamicReturnTypeExtension
service helps to determine the type of the entity which is
loaded, created etc.. when using an entity storage.
For instance when using
It helps with knowing the type of the $node
variable is Drupal\node\Entity\Node
.
The default mapping can be found in extension.neon
:
To add support for custom entities, you may add the same definition in your project's phpstan.neon
likewise.
Providing entity type mappings for a contrib module
Contributed modules can provide their own mapping that can be automatically registered with a user's code base when
they use the phpstan/extension-installer
. The extension installer scans installed package's composer.json
for a
value in extra.phpstan
. This will automatically bundle the defined include that contains an entity mapping
configuration.
For example, the Paragraphs module could have the following entity_mapping.neon
file:
Then in the composer.json
for Paragraphs, the entity_mapping.neon
would be provided as a PHPStan include
All versions of phpstan-drupal with dependencies
phpstan/phpstan Version ^1.10.56
phpstan/phpstan-deprecation-rules Version ^1.1.4
symfony/finder Version ^4.2 || ^5.0 || ^6.0 || ^7.0
symfony/yaml Version ^4.2|| ^5.0 || ^6.0 || ^7.0
webflo/drupal-finder Version ^1.3.1