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

Aperta
#191 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
php
Ambito
devtools

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
PHP
Stelle
185
Fork
33
Merge medio
20h 40m
PR unite (30g)
7

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di phpstan/phpstan-webmozart-assert

Tutte le issue di phpstan/phpstan-webmozart-assert

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.