TenantChoiceType   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 5
dl 0
loc 57
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A buildForm() 0 6 2
A configureOptions() 0 10 1
A getParent() 0 4 1
A getBlockPrefix() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher MultiTenancy Bundle.
7
 *
8
 * Copyright 2017 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2017 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\MultiTenancyBundle\Form\Type;
18
19
use SWP\Component\MultiTenancy\Repository\TenantRepositoryInterface;
20
use Symfony\Bridge\Doctrine\Form\DataTransformer\CollectionToArrayTransformer;
21
use Symfony\Component\Form\AbstractType;
22
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
23
use Symfony\Component\Form\FormBuilderInterface;
24
use Symfony\Component\OptionsResolver\Options;
25
use Symfony\Component\OptionsResolver\OptionsResolver;
26
27
final class TenantChoiceType extends AbstractType
28
{
29
    /**
30
     * @var TenantRepositoryInterface
31
     */
32
    private $tenantRepository;
33
34
    /**
35
     * TenantChoiceType constructor.
36
     *
37
     * @param TenantRepositoryInterface $tenantRepository
38
     */
39
    public function __construct(TenantRepositoryInterface $tenantRepository)
40
    {
41
        $this->tenantRepository = $tenantRepository;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function buildForm(FormBuilderInterface $builder, array $options)
48
    {
49
        if ($options['multiple']) {
50
            $builder->addModelTransformer(new CollectionToArrayTransformer());
51
        }
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function configureOptions(OptionsResolver $resolver)
58
    {
59
        $resolver->setDefaults([
60
            'choices' => function (Options $options) {
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
61
                return $this->tenantRepository->findAll();
62
            },
63
            'choice_value' => 'code',
64
            'choice_label' => 'name',
65
        ]);
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function getParent()
72
    {
73
        return ChoiceType::class;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function getBlockPrefix()
80
    {
81
        return '';
82
    }
83
}
84