Passed
Pull Request — master (#119)
by Arnaud
05:32
created

FormEvent::removeFieldDefinition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace LAG\AdminBundle\Event\Events;
4
5
use LAG\AdminBundle\Event\AbstractEvent;
6
use LAG\AdminBundle\Exception\Exception;
7
use LAG\AdminBundle\Field\Definition\FieldDefinition;
8
use LAG\AdminBundle\Field\Definition\FieldDefinitionInterface;
9
use Symfony\Component\Form\FormInterface;
10
11
class FormEvent extends AbstractEvent
12
{
13
    /**
14
     * @var FormInterface[]
15
     */
16
    private $forms = [];
17
18
    /**
19
     * @var FieldDefinitionInterface[]
20
     */
21
    private $definitions = [];
22
23
    /**
24
     * @param FormInterface $form
25
     * @param string        $identifier
26
     *
27
     * @throws Exception
28
     */
29
    public function addForm(FormInterface $form, string $identifier)
30
    {
31
        if (array_key_exists($identifier, $this->forms)) {
32
            throw new Exception('A form with the identifier "'.$identifier.'" was already added');
33
        }
34
        $this->forms[$identifier] = $form;
35
    }
36
37
    /**
38
     * @return FormInterface[]
39
     */
40
    public function getForms()
41
    {
42
        return $this->forms;
43
    }
44
45
    public function addFieldDefinition(string $name, FieldDefinitionInterface $definition): void
46
    {
47
        $this->definitions[$name] = $definition;
48
    }
49
50
    public function removeFieldDefinition(string $name): void
51
    {
52
        unset($this->definitions[$name]);
53
    }
54
55
    /**
56
     * @return FieldDefinition[]
57
     */
58
    public function getFieldDefinitions(): array
59
    {
60
        return $this->definitions;
61
    }
62
}
63