Closed jakubvojacek closed 1 year ago
It should be enough to typehint that getRenderer()
in your app returns more specific type that has these methods. Either directly in your code (BaseForm
) or in PHPStan stubs. Something like this:
/**
* @method \Nette\Forms\RenderingDefaultFormRenderer getRenderer()
*/
class Form {
yes,
/**
* @method \Nette\Forms\Rendering\DefaultFormRenderer getRenderer()
*/
worked like a charm. Thanks a lot :+1:
This stopped working, I guess it was caused by https://github.com/efabrica-team/phpstan-latte/commit/e73d5f281b8b77f0b7739965be447253b0d73084 (since this commit was related to forms, not sure tho).
Anyhow, now the dev-main
reports again
40 Call to an undefined method Nette\Forms\FormRenderer::renderPair().
43 Call to an undefined method Nette\Forms\FormRenderer::renderPair().
46 Call to an undefined method Nette\Forms\FormRenderer::renderPair().
51 Call to an undefined method Nette\Forms\FormRenderer::renderPair().
54 Call to an undefined method Nette\Forms\FormRenderer::renderPair().
57 Call to an undefined method Nette\Forms\FormRenderer::renderPair().
61 Call to an undefined method Nette\Forms\FormRenderer::renderPair().
even when I used the phpdocs
/** @method CSMSFormRender getRenderer() */
class CSMSForm extends \Nette\Application\UI\Form
{
...
@lulco I think error is maybe here https://github.com/efabrica-team/phpstan-latte/blob/314ee555a0cb268ec86b172542f11cc33f6fa541/src/Compiler/LatteToPhpCompiler.php#L163 it should extend given form class not basic nette form.
Yes, we don't collect Form type now. Adding to list in https://github.com/efabrica-team/phpstan-latte/issues/106
@jakubvojacek @MartinMystikJonas
Fixed in https://github.com/efabrica-team/phpstan-latte/pull/115
Some problems can be found:
Can we generate PHPStan stubs and pass them to analyser when analysisng templates?
Not sure... Method FileAnalyser::analyseFile()
has second parameter array $analysedFiles. I was trying to add some files there several times but always failed.
I just tested this branch on my codebase and it was much better, no more errors :+1:
@jakubvojacek ok thanks, @MartinMystikJonas please CR and we can merge
Hello
we use custom formRender (extending
Nette\Forms\Rendering
implementingNette\Forms\FormRenderer
)It has methods such as
renderPair, renderControls, ...
We use it directly in lattes sometimes, eg
or
which results in phpstan complaining about
I can add these errors into my phpstan ignore list. But I was wondering if this should be done at the phpstan-latte level? Since
Nette\Forms\RenderingDefaultFormRenderer
which is used by default implements all these methods?Thanks