SelectFormProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 2
eloc 12
c 1
b 1
f 0
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A addTypeToForm() 0 17 2
1
<?php
2
3
4
namespace oliverde8\ComfyBundle\Resolver\Form;
5
6
7
use oliverde8\ComfyBundle\Exception\InvalidConfigTypeForFormProvider;
8
use oliverde8\ComfyBundle\Model\ConfigInterface;
9
use oliverde8\ComfyBundle\Model\SelectConfig;
10
use Symfony\Component\Form\FormBuilderInterface;
11
use Symfony\Component\Form\FormInterface;
12
13
class SelectFormProvider extends SimpleFormProvider
14
{
15
    /**
16
     * @inheritdoc
17
     */
18
    public function addTypeToForm(string $name, ConfigInterface $config, FormBuilderInterface $formBuilder, string $scope)
19
    {
20
        if (!($config instanceof SelectConfig)) {
21
            throw new InvalidConfigTypeForFormProvider(
22
                sprintf("Config is expected to be of type %s but is of type %s", SelectConfig::class, get_class($config))
23
            );
24
        }
25
26
        $formBuilder->add(
27
            $name,
28
            $this->formType,
29
            [
30
                'label' => $config->getName(),
31
                'help' => $this->getHelpHtml($config, $scope),
32
                'data' => $config->get($scope),
33
                'choices'  => $config->getOptions(),
34
                'multiple' => $config->isAllowMultiple(),
35
            ],
36
        );
37
    }
38
}
39