fix: SA: Fix "might not be defined" rule.

SA stands for Static Analysis.
This commit is contained in:
Pol Dellaiera
2021-11-16 11:41:12 +01:00
parent a7b96f1756
commit f8aeb08594
14 changed files with 365 additions and 620 deletions

View File

@@ -2,6 +2,7 @@
namespace Chill\CustomFieldsBundle\Form;
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -15,7 +16,7 @@ use Chill\MainBundle\Form\Type\TranslatableStringFormType;
class CustomFieldsGroupType extends AbstractType
{
private $customizableEntities; //TODO : add comment about this variable
/**
@@ -52,50 +53,48 @@ class CustomFieldsGroupType extends AbstractType
))
;
$builder->addEventListener(FormEvents::POST_SET_DATA,
function(FormEvent $event) use ($customizableEntities, $builder){
$form = $event->getForm();
$group = $event->getData();
$builder->addEventListener(
FormEvents::POST_SET_DATA,
function(FormEvent $event) use ($customizableEntities, $builder) {
$form = $event->getForm();
$group = $event->getData();
//stop the function if entity is not set
if ($group->getEntity() === NULL) {
return;
}
//stop the function if entity is not set
if ($group->getEntity() === NULL) {
return;
}
if (count($customizableEntities[$group->getEntity()]['options']) > 0) {
$optionBuilder = $builder
->getFormFactory()
->createBuilderForProperty(
'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup',
'options'
)
->create('options', null, array(
'compound' => true,
'auto_initialize' => false,
'required' => false)
);
}
$optionBuilder = null;
if (count($customizableEntities[$group->getEntity()]['options']) > 0) {
$optionBuilder = $builder
->getFormFactory()
->createBuilderForProperty(CustomFieldsGroup::class, 'options')
->create(
'options',
null,
[
'compound' => true,
'auto_initialize' => false,
'required' => false
]
);
foreach($customizableEntities[$group->getEntity()]['options'] as $key => $option) {
$optionBuilder
->add($key, $option['form_type'], $option['form_options'])
;
}
if (isset($optionBuilder) && $optionBuilder->count() > 0) {
$form->add($optionBuilder->getForm());
$optionBuilder->add($key, $option['form_type'], $option['form_options']);
}
}
});
if ((null !== $optionBuilder) && $optionBuilder->count() > 0) {
$form->add($optionBuilder->getForm());
}
});
}
/**
* @param OptionsResolverInterface $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup'
));
$resolver->setDefaults([
'data_class' => CustomFieldsGroup::class,
]);
}
/**