SiteType   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 1
b 0
f 0
dl 0
loc 23
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configureOptions() 0 8 1
A getParent() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FH\Bundle\MultiSiteBundle\Form\Type;
6
7
use FH\Bundle\MultiSiteBundle\Site\SiteInterface;
8
use FH\Bundle\MultiSiteBundle\Site\SiteRepositoryInterface;
9
use Symfony\Component\Form\AbstractType;
10
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
11
use Symfony\Component\OptionsResolver\OptionsResolver;
12
13
/**
14
 * @author Joris van de Sande <[email protected]>
15
 */
16
final class SiteType extends AbstractType
17
{
18
    private $siteRepository;
19
20
    public function __construct(SiteRepositoryInterface $siteRepository)
21
    {
22
        $this->siteRepository = $siteRepository;
23
    }
24
25
    public function configureOptions(OptionsResolver $resolver): void
26
    {
27
        $resolver->setDefaults([
28
            'choices' => $this->siteRepository->findAll(),
29
            'choice_label' => static function (?SiteInterface $site = null) {
30
                return (string) $site;
31
            },
32
            'choice_value' => 'id',
33
        ]);
34
    }
35
36
    public function getParent(): string
37
    {
38
        return ChoiceType::class;
39
    }
40
}
41