False positive: Call to static method Webmozart\Assert\Assert::allInArray() with array<string> and array<string> will always evaluate to true

Offen
#191 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
45/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
php
Bereich
devtools

Rechercherichtung

Start with the test.php reproduction and run the shown PHPStan command using phpstan.neon at level 4. Inspect the phpstan-webmozart-assert extension configuration and the discussion in issue 142; done means this example no longer reports staticMethod.alreadyNarrowedType while the assertion analysis remains correct.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

The following code causes a false PHPStan error. The Assert::allInArray($enabledNames, $supportedNames); assertion certainly isn't always true.

use Webmozart\Assert\Assert;

class C
{
    /**
     * @param array<string> $supportedNames
     * @param array<string> $enabledNames
     */
    public function __construct(
        array $supportedNames,
        array $enabledNames,
    )
    {
        Assert::allInArray($enabledNames, $supportedNames);
    }
}
$ vendor/bin/phpstan analyse -c phpstan.neon test.php
 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 ------ --------------------------------------------------------------------------------------------------------------------------------
  Line   test.php
 ------ --------------------------------------------------------------------------------------------------------------------------------
  17     Call to static method Webmozart\Assert\Assert::allInArray() with array<string> and array<string> will always evaluate to true.
         🪪  staticMethod.alreadyNarrowedType
 ------ --------------------------------------------------------------------------------------------------------------------------------



 [ERROR] Found 1 error


===============


$ vendor/bin/phpstan diagnose
Note: Using configuration file /Users/melka/work/rh/phpstan.neon.
PHP runtime version: 8.3.22
PHP version for analysis: 8.3.22 (from runtime)

PHPStan version: 2.1.29
PHPStan running from:
/Users/melka/work/rh/vendor/phpstan/phpstan

Extension installer: Not installed

Included configs from Composer packages:
phpstan/phpstan-webmozart-assert (extension.neon): 2.0.0

Discovered Composer project root:
/Users/melka/work/rh


===============


$ cat phpstan.neon
includes:
    - vendor/phpstan/phpstan-webmozart-assert/extension.neon
parameters:
    level: 4  # lowest level where this starts happening

Also discussed in https://github.com/phpstan/phpstan-webmozart-assert/issues/142#issuecomment-3372330454

Vorherrschende Sprache
PHP
Sterne
185
Forks
33
Ø Merge
20 Std. 40 Min.
Gemergte PRs (30 T.)
7

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus phpstan/phpstan-webmozart-assert

Alle Issues in phpstan/phpstan-webmozart-assert

Ähnliche Issues

Weitere Issues zu PHP

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.