Failed Conditions
CANCELLED  
Pull Request — master (#7095)
by Benjamin
10:13
created

EntityClassMetadata::getNamedNativeQuery()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 0
cts 6
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM\Mapping;
6
7
use function sprintf;
8
9
/**
10
 * Class EntityClassMetadata
11
 *
12
 */
13
abstract class EntityClassMetadata extends ComponentMetadata
14
{
15
    /** @var string The name of the Entity */
16
    protected $entityName;
17
18
    /**
19
     * @var string|null The name of the custom repository class used for the entity class.
20
     */
21
    protected $customRepositoryClassName;
22
23
    /**
24
     * @var Property|null The field which is used for versioning in optimistic locking (if any).
25
     */
26
    protected $declaredVersion;
27
28
    /**
29
     * Whether this class describes the mapping of a read-only class.
30
     * That means it is never considered for change-tracking in the UnitOfWork.
31
     * It is a very helpful performance optimization for entities that are immutable,
32
     * either in your domain or through the relation database (coming from a view,
33
     * or a history table for example).
34
     *
35
     * @var bool
36
     */
37
    protected $readOnly = false;
38
39
    /**
40
     * List of all sub-classes (descendants) metadata.
41
     *
42
     * @var SubClassMetadata[]
43
     */
44
    protected $subClasses = [];
45
46
    /**
47
     * READ-ONLY: The registered lifecycle callbacks for entities of this class.
48
     *
49
     * @var string[][]
50
     */
51
    protected $lifecycleCallbacks = [];
52
53
    /**
54
     * READ-ONLY: The registered entity listeners.
55
     *
56
     * @var string[][]
57
     */
58
    protected $entityListeners = [];
59
60
    /**
61
     * READ-ONLY: The field names of all fields that are part of the identifier/primary key
62
     * of the mapped entity class.
63
     *
64
     * @var string[]
65
     */
66
    protected $identifier = [];
67
68
    /**
69
     * READ-ONLY: The primary table metadata.
70
     *
71
     * @var TableMetadata
72
     */
73
    protected $table;
74
75
    public function __construct(string $className, ClassMetadataBuildingContext $metadataBuildingContext)
76
    {
77
        parent::__construct($className, $metadataBuildingContext);
78
79
        $this->entityName = $className;
80
    }
81
82
    public function getEntityName() : string
83
    {
84
        return $this->entityName;
85
    }
86
87
    public function setEntityName(string $entityName) : void
88
    {
89
        $this->entityName = $entityName;
90
    }
91
92
    public function getCustomRepositoryClassName() : ?string
93
    {
94
        return $this->customRepositoryClassName;
95
    }
96
97
    public function setCustomRepositoryClassName(?string $customRepositoryClassName) : void
98
    {
99
        $this->customRepositoryClassName = $customRepositoryClassName;
100
    }
101
102
    public function getDeclaredVersion() : ?Property
103
    {
104
        return $this->declaredVersion;
105
    }
106
107
    public function setDeclaredVersion(Property $property) : void
108
    {
109
        $this->declaredVersion = $property;
110
    }
111
112
    public function getVersion() : ?Property
113
    {
114
        /** @var ComponentMetadata|null $parent */
115
        $parent  = $this->parent;
116
        $version = $this->declaredVersion;
117
118
        if ($parent && ! $version) {
119
            $version = $parent->getVersion();
0 ignored issues
show
Bug introduced by
The method getVersion() does not exist on Doctrine\ORM\Mapping\ComponentMetadata. It seems like you code against a sub-type of Doctrine\ORM\Mapping\ComponentMetadata such as Doctrine\ORM\Mapping\MappedSuperClassMetadata or Doctrine\ORM\Mapping\EntityClassMetadata. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

119
            /** @scrutinizer ignore-call */ 
120
            $version = $parent->getVersion();
Loading history...
120
        }
121
122
        return $version;
123
    }
124
125
    public function isVersioned() : bool
126
    {
127
        return $this->getVersion() !== null;
128
    }
129
130
    public function setReadOnly(bool $readOnly) : void
131
    {
132
        $this->readOnly = $readOnly;
133
    }
134
135
    public function isReadOnly() : bool
136
    {
137
        return $this->readOnly;
138
    }
139
140
    /**
141
     * @throws MappingException
142
     */
143
    public function addSubClass(SubClassMetadata $subClassMetadata) : void
144
    {
145
        /** @var EntityClassMetadata|null $superClassMetadata */
146
        $superClassMetadata = $this->getParent();
147
148
        while ($superClassMetadata !== null) {
149
            if ($superClassMetadata->entityName === $subClassMetadata->entityName) {
150
                throw new MappingException(
151
                    sprintf(
152
                        'Circular inheritance mapping detected: "%s" have itself as superclass when extending "%s".',
153
                        $subClassMetadata->entityName,
154
                        $superClassMetadata->entityName
155
                    )
156
                );
157
            }
158
159
            $superClassMetadata->subClasses[] = $subClassMetadata;
160
161
            $superClassMetadata = $superClassMetadata->parent;
162
        }
163
164
        $this->subClasses[] = $subClassMetadata;
165
    }
166
167
    public function hasSubClasses() : bool
168
    {
169
        return (bool) $this->subClasses;
170
    }
171
172
    public function getSubClassIterator() : \Iterator
173
    {
174
        $iterator = new \AppendIterator();
175
176
        foreach ($this->subClasses as $subClassMetadata) {
177
            $iterator->append($subClassMetadata->getSubClassIterator());
178
        }
179
180
        $iterator->append(new \ArrayIterator($this->subClasses));
181
182
        return $iterator;
183
    }
184
185
    /**
186
     * {@inheritdoc}
187
     */
188
    public function addDeclaredProperty(Property $property) : void
189
    {
190
        parent::addDeclaredProperty($property);
191
192
        if ($property instanceof VersionFieldMetadata) {
193
            $this->setDeclaredVersion($property);
194
        }
195
    }
196
197
    abstract public function getRootClass() : RootClassMetadata;
198
}
199