Completed
Push — 3.x ( 8a92d8...567b58 )
by Grégoire
04:36
created

TestExtension::addType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Tests\Fixtures;
15
16
use Symfony\Component\Form\FormExtensionInterface;
17
use Symfony\Component\Form\FormTypeExtensionInterface;
18
use Symfony\Component\Form\FormTypeGuesserInterface;
19
use Symfony\Component\Form\FormTypeInterface;
20
21
class TestExtension implements FormExtensionInterface
22
{
23
    private $types = [];
24
25
    private $extensions = [];
26
27
    private $guesser;
28
29
    public function __construct(FormTypeGuesserInterface $guesser)
30
    {
31
        $this->guesser = $guesser;
32
    }
33
34
    public function addType(FormTypeInterface $type)
35
    {
36
        $this->types[\get_class($type)] = $type;
37
    }
38
39
    public function getType($name): FormTypeInterface
40
    {
41
        return isset($this->types[$name]) ? $this->types[$name] : null;
42
    }
43
44
    public function hasType($name): bool
45
    {
46
        return isset($this->types[$name]);
47
    }
48
49
    public function addTypeExtension(FormTypeExtensionInterface $extension)
50
    {
51
        foreach ($extension::getExtendedTypes() as $type) {
52
            if (!isset($this->extensions[$type])) {
53
                $this->extensions[$type] = [];
54
            }
55
56
            $this->extensions[$type][] = $extension;
57
        }
58
    }
59
60
    public function getTypeExtensions($name): array
61
    {
62
        return isset($this->extensions[$name]) ? $this->extensions[$name] : [];
63
    }
64
65
    public function hasTypeExtensions($name): bool
66
    {
67
        return isset($this->extensions[$name]);
68
    }
69
70
    public function getTypeGuesser(): ?FormTypeGuesserInterface
71
    {
72
        return $this->guesser;
73
    }
74
}
75