Method Drupal\Core\Form\FormBuilderInterface::getForm() invoked with 2 parameters, 1 required.

Aperta
#892 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #957 di @marklabrecque-ab — chiusa senza merge

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
drupal, php

Direzione di ricerca

Start by comparing Drupal 10.5's FormBuilderInterface::getForm() signature and the PHPStan Drupal rules that report its accepted parameters; the issue links to core's SystemController.php and ThemeAdminForm.php as examples. Check how the analyzer handles those calls at PHPStan level 2, then confirm whether the reported call is accepted or produces a false positive. Done means the discrepancy is explained and, if it is a bug, covered by a regression test.

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

Descrizione

bug

Bug report

In my project (currently on Drupal 10.5.1), I'm adding an extra parameter in getForm() like this:

$this->formBuilder->getForm(AccountLoginForm::class, ['param_here' => 'value_here']);

Then in AccountLoginForm.php, I have this:

buildForm(array $form, FormStateInterface $form_state, ?array $options = NULL)

I would then use $options['param_here'] in my form. Which all works perfectly... however I'm getting this phpstan error when running a scan:

Method Drupal\Core\Form\FormBuilderInterface::getForm() invoked with 2 parameters, 1 required.

What doesn't make sense to me though...is that I see Drupal core (10.5.x.) doing this as well. For example, in SystemController.php which is calling this form.

I'm doing the same thing here... so I guess I'm a little confused as to why I'm seeing this error?

The one thing I thought of though...is that Drupal core is using level 1 in their phpstan file (whereas I'm using level 2 in my project). I don't know if that should really matter though?

I do see in the 10.x documentation that getForm() should only have 1 parameter (11.x does show the 2nd parameter) however...then why is core (10.5.x) using that 2nd parameter? I'm following what core is doing, so I'm a little surprised that I'm running into this problem. Is this an actual bug then?

Lingua principale
PHP
Stelle
208
Fork
88
Merge medio
2g 17h
PR unite (30g)
15

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 mglaman/phpstan-drupal

Tutte le issue di mglaman/phpstan-drupal

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.