New checking in mglaman/phpstan-drupal interfering with our usage of \Drupal\Component\Assertion\Inspector

Created on 9 April 2025, 12 days ago

Problem/Motivation

Since the merge of mglaman/phpstan-drupal's 826 and 834, we're getting PHPStan fails in certain configurations, see https://git.drupalcode.org/project/project_browser/-/jobs/4904808

Steps to reproduce

Chaining multiple Inspector calls is failing PHPStan:

    assert(
      Inspector::assertAllArrays($images) &&
      Inspector::assertAll(fn (array $i): bool => $i['file'] instanceof Url, $images) &&
      Inspector::assertAllHaveKey($images, 'alt')
    ) or throw new \InvalidArgumentException('The project images must be arrays with `file` and `alt` elements.');

On D10.5.x, using PHPStan 2.1.11 and PHPStan-Drupal 2.0.2 (or later)

 ------ -------------------------------------------------------------------------
  Line   src/ProjectBrowser/Project.php
 ------ -------------------------------------------------------------------------
  101    Call to static method Drupal\Component\Assertion\Inspector::assertAll()
         with Closure(array): bool and array<mixed, array<mixed, mixed>> will
         always evaluate to false.
         πŸͺͺ  staticMethod.impossibleType
  102    Call to static method
         Drupal\Component\Assertion\Inspector::assertAllHaveKey() with *NEVER*
         and 'alt' will always evaluate to true.
         πŸͺͺ  staticMethod.alreadyNarrowedType
 ------ -------------------------------------------------------------------------

On D11.1.3, using PHPStan 1.12.23 and PHPStan-Drupal 1.3.4 (or later)

 ------ -------------------------------------------------------------------------
  Line   src/ProjectBrowser/Project.php
 ------ -------------------------------------------------------------------------
  101    Call to static method Drupal\Component\Assertion\Inspector::assertAll()
         with Closure(array): bool and array<array> will always evaluate to
         false.
         πŸͺͺ  staticMethod.impossibleType
 ------ -------------------------------------------------------------------------

Proposed resolution

Short term, we could pin to 1.3.3/2.0.1
Long term, either figure out what we're doing wrong or get a fix in upstream

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States tim.plunkett Philadelphia

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024