Skip to content

False positive for normalizer in method call in setNormalizer #194

@judzi

Description

@judzi

Description:
The dependency analyzer seems to flag the normalizer argument in the OptionsResolver::setNormalizer method as an unknown class, even though it's a named argument. This appears to be a false positive caused by misinterpretation of named arguments as class names.

Steps to Reproduce:

  1. Create the following PHP code:

    <?php declare(strict_types=1); namespace App; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\OptionsResolver\OptionsResolver; use function array_merge; final class FooType extends ChoiceType { public function configureOptions(OptionsResolver $resolver): void { parent::configureOptions($resolver); $resolver->setNormalizer( option: 'attr', normalizer: static fn ($options, $value) => array_merge( ['foo' => 'bar'], $value, ), ); } }
  2. Run the analyzer.

  3. Observe the output:

    Found 1 unknown class! (unable to autoload those, so we cannot check them) • normalizer in src/FooType.php:20 
  4. Update the method call to use positional arguments instead of named arguments:

    $resolver->setNormalizer( 'attr', static fn ($options, $value) => array_merge( ['foo' => 'bar'], $value, ), );
  5. Run the analyzer again. This time, no errors are reported.

Environment:

  • PHP version: 8.3.11
  • symfony/form package version: 7.1.6
  • symfony/options-resolver package version: 7.1.6
  • Composer Dependency Analyzer version: 1.8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions