__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 5
1
<?php
2
3
namespace steevanb\DoctrineEvents\Doctrine\ORM\Event;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
7
class OnCreateEntityDefineFieldValuesEventArgs extends AbstractOnCreateEntityEventArgs
8
{
9
    const EVENT_NAME = 'onCreateEntityDefineFieldValues';
10
11
    /** @var object */
12
    protected $entity;
13
14
    /** @var string */
15
    protected $definedFieldValues = [];
16
17
    /**
18
     * @param EntityManagerInterface $em
19
     * @param string $className
20
     * @param array $data
21
     * @param array $hints
22
     * @param object $entity
23
     */
24
    public function __construct(
25
        EntityManagerInterface $em,
26
        $className,
27
        array $data,
28
        array $hints,
29
        $entity
30
    ) {
31
        parent::__construct($em, $className, $data, $hints);
32
        $this->entity = $entity;
33
    }
34
35
    /** @return object */
36
    public function getEntity()
37
    {
38
        return $this->entity;
39
    }
40
41
    /**
42
     * @param string $field
43
     * @return $this
44
     */
45
    public function addDefinedFieldValue($field)
46
    {
47
        $this->definedFieldValues[$field] = true;
48
49
        return $this;
50
    }
51
52
    /** @return string[] */
53
    public function getDefinedFieldValues()
54
    {
55
        return array_keys($this->definedFieldValues);
56
    }
57
58
    /**
59
     * @param string $field
60
     * @return bool
61
     */
62
    public function isValueDefined($field)
63
    {
64
        return isset($this->definedFieldValues[$field]);
65
    }
66
}
67