Add entity_mappings for phpstan-drupal (3.2.x)

Created on 26 October 2023, about 1 year ago

Problem/Motivation

The phpstan-drupal extension for PHPStan allows defining information about entity types to improve static analysis of Drupal code. For instance, knowing what entity storage class is returned from the entity type manager and the entity class returned from create/load methods.

Using a configuration file and a definition the composer.json, Group can provide this information. The information will be picked up by phpstan/extension-installer.

In addition to allowing static analysis of the Group module itself using phpstan/phpstan-drupal, this information will allow static analysis of other modules that integrate with Group to properly determine the available methods on Group's entities when they are returned by the EntityTypeManager.

See the phpstan-drupal README and this phpstan-drupal issue for additional context https://github.com/mglaman/phpstan-drupal/issues/281

Proposed resolution

Create an entity_mapping.neon file and register it in the composer.json for phpstan/extension-installer

Testing instructions

  1. Create a new drupal codebase:
    composer create-project drupal/recommended-project drupal
    cd drupal/
  2. Set up the issue fork as Composer source:
    composer config repositories.group vcs https://git.drupalcode.org/issue/group-3397015.git
  3. Add group with:
    composer require drupal/group:dev-3397015-entitymappings-phpstan
  4. Review vendor/phpstan/extension-installer/src/GeneratedConfig.php and verify Group's config is included
  5. Analyze Group code, ensure no crashes: vendor/bin/phpstan analyse web/modules/contrib/group/
✨ Feature request
Status

Active

Version

3.2

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States adamfranco

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024