Your project must not contain invalid function or method calls 10
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_call
- 'trim' => true,
- ])
- ->setAllowedTypes('lookup_field', 'string')
- ->setNormalizer('lookup_field', function (Options $options, string $lookupField): string {
- // fails early, when form is built, if class or lookup field is invalid
- $this->getManager($options['class'], $lookupField);
- return $lookupField;
- });
- }
- $resolver
- ->setDefaults([
- 'label_field' => null,
- 'placeholder' => '---',
- 'translation_domain' => false,
- 'choices' => fn (Options $options): array => $this->getChoices($options['class'], $options['lookup_field'], $options['label_field']),
- ])
- ->setAllowedTypes('label_field', ['null', 'string']);
- }
- /**
- $resolver
- ->setDefaults([
- 'label_field' => null,
- 'placeholder' => '---',
- 'translation_domain' => false,
- 'choices' => fn (Options $options): array => $this->getChoices($options['class'], $options['lookup_field'], $options['label_field']),
- ])
- ->setAllowedTypes('label_field', ['null', 'string']);
- }
- /**
- $resolver
- ->setDefaults([
- 'label_field' => null,
- 'placeholder' => '---',
- 'translation_domain' => false,
- 'choices' => fn (Options $options): array => $this->getChoices($options['class'], $options['lookup_field'], $options['label_field']),
- ])
- ->setAllowedTypes('label_field', ['null', 'string']);
- }
- /**
- if (isset($this->choicesCache[$cacheKey])) {
- return $this->choicesCache[$cacheKey];
- }
- $manager = $this->getManager($class, $lookupField);
- if (null !== $labelField && !$manager->getClassMetadata($class)->hasField($labelField)) {
- throw new InvalidOptionsException(\sprintf('Field "%s" does not exist in entity "%s".', $labelField, $class));
- }
- $choices = [];
- foreach ($this->loadValuesAndLabels($manager, $class, $lookupField, $labelField) as [$value, $label]) {
- if (isset($this->choicesCache[$cacheKey])) {
- return $this->choicesCache[$cacheKey];
- }
- $manager = $this->getManager($class, $lookupField);
- if (null !== $labelField && !$manager->getClassMetadata($class)->hasField($labelField)) {
- throw new InvalidOptionsException(\sprintf('Field "%s" does not exist in entity "%s".', $labelField, $class));
- }
- $choices = [];
- foreach ($this->loadValuesAndLabels($manager, $class, $lookupField, $labelField) as [$value, $label]) {
- // bundle supports only Doctrine ORM, see AbstractImportConfiguration
- \assert($manager instanceof EntityManagerInterface);
- $queryBuilder = $manager->createQueryBuilder()
- ->select('e.' . $lookupField . ' AS value')
- ->from($class, 'e');
- if (null !== $labelField) {
- $queryBuilder->addSelect('e.' . $labelField . ' AS label');
- }
- /** @var array{value: string|int|null, label?: scalar|null} $row */
- $manager = $this->getManagerForClass($class);
- if (!$manager) {
- throw new InvalidArgumentException(\sprintf('Class "%s" is not a managed Doctrine entity.', $class));
- }
- if (!$manager->getClassMetadata($class)->hasField($lookupField)) {
- throw new InvalidArgumentException(\sprintf('Field "%s" does not exist in entity "%s".', $lookupField, $class));
- }
- return $manager;
- }
- $manager = $this->getManagerForClass($class);
- if (!$manager) {
- throw new InvalidArgumentException(\sprintf('Class "%s" is not a managed Doctrine entity.', $class));
- }
- if (!$manager->getClassMetadata($class)->hasField($lookupField)) {
- throw new InvalidArgumentException(\sprintf('Field "%s" does not exist in entity "%s".', $lookupField, $class));
- }
- return $manager;
- }
- }
- private function getManagerForClass(string $class): ?ObjectManager
- {
- if ($this->managers instanceof ManagerRegistry) {
- return $this->managers->getManagerForClass($class);
- }
- return \class_exists($class) && !$this->managers->getMetadataFactory()->isTransient($class)
- ? $this->managers
- : null;
Your project must not contain invalid instantiations 2
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_instantiation
- $resolver->setNormalizer(
- 'constraints',
- static function (Options $options, mixed $constraints): array {
- /** @var Constraint[] $constraints */
- $constraints = \is_array($constraints) ? $constraints : [$constraints];
- $constraints[] = new RelatedEntityExists(class: $options['class'], lookupField: $options['lookup_field']);
- return $constraints;
- },
- );
- }
- $resolver->setNormalizer(
- 'constraints',
- static function (Options $options, mixed $constraints): array {
- /** @var Constraint[] $constraints */
- $constraints = \is_array($constraints) ? $constraints : [$constraints];
- $constraints[] = new RelatedEntityExists(class: $options['class'], lookupField: $options['lookup_field']);
- return $constraints;
- },
- );
- }