Completed
Pull Request — master (#29)
by Yann
10:30
created

TestExtension::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace Yokai\Enum\Tests\Bridge\Symfony\Form;
4
5
use Symfony\Component\Form\AbstractExtension;
6
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
7
use Yokai\Enum\Bridge\Symfony\Form\Type\EnumType;
8
use Yokai\Enum\Bridge\Symfony\Form\Extension\EnumTypeGuesser;
9
use Yokai\Enum\EnumRegistry;
10
11
/**
12
 * @author Yann Eugoné <[email protected]>
13
 */
14
class TestExtension extends AbstractExtension
15
{
16
    /**
17
     * @var EnumRegistry
18
     */
19
    private $enumRegistry;
20
21
    /**
22
     * @var MetadataFactoryInterface|null
23
     */
24
    private $metadataFactory;
25
26
    /**
27
     * @param EnumRegistry                  $enumRegistry
28
     * @param MetadataFactoryInterface|null $metadataFactory
29
     */
30
    public function __construct(EnumRegistry $enumRegistry, MetadataFactoryInterface $metadataFactory = null)
31
    {
32
        $this->enumRegistry = $enumRegistry;
33
        $this->metadataFactory = $metadataFactory;
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39
    protected function loadTypes()
40
    {
41
        return [
42
            new EnumType($this->enumRegistry),
43
        ];
44
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49
    protected function loadTypeGuesser()
50
    {
51
        if ($this->metadataFactory === null) {
52
            return null;
53
        }
54
55
        return new EnumTypeGuesser($this->metadataFactory, $this->enumRegistry);
56
    }
57
}
58