[Feature request] Check if certain option is set on each form
ThomasLandauer opened this issue · 4 comments
I'd like to check if the option csrf_protection is set on each form explicitly, to make sure I haven't forgot one.
Are checks of this kind possible with PHPStan at all?
P.S.: I know that form options can be configured globally, but I'd like to make sure that my forms work independently of global settings.
Please show a piece of code that's supposed to report an error, and then a piece of code that would fix the problem.
This should pass:
// In every src/Form/*Type.php:
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'csrf_protection' => false,
]);
}And it should fail if:
configureOptions()isn't present,- or
$resolver->setDefaults()isn't present, - or
csrf_protectionisn't set inside thesetDefaults()array
Yeah, this is doable, you can implement a custom rule for yourself: https://phpstan.org/developing-extensions/rules
I offer implementing custom rules for a fee, starting at 500 EUR, let me know if you're interested 😊
But this isn't a good fit for phpstan-symfony, because omitting CSRF protection isn't a bug. If it was a bug then Symfony would not make it optional. Thanks for understanding.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.