Completed
Pull Request — master (#5938)
by Maximilian
16:49 queued 08:43
created

testIdentifierColumnDefinition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\ORM\Mapping;
4
5
use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService;
6
use Doctrine\ORM\EntityManager;
7
use Doctrine\ORM\Events;
8
use Doctrine\ORM\Mapping\ClassMetadataFactory;
9
use Doctrine\ORM\Mapping\DiscriminatorColumn;
10
use Doctrine\ORM\Mapping\Id;
11
use Doctrine\ORM\Mapping\MappingException;
12
use Doctrine\ORM\Mapping\UnderscoreNamingStrategy;
13
use Doctrine\Tests\Models\Cache\City;
14
use Doctrine\ORM\Mapping\ClassMetadata;
15
use Doctrine\ORM\Mapping\ClassMetadataInfo;
16
use Doctrine\Tests\Models\DDC2825\ExplicitSchemaAndTable;
17
use Doctrine\Tests\Models\DDC2825\SchemaAndTableInTableName;
18
use Doctrine\Tests\OrmTestCase;
19
20
abstract class AbstractMappingDriverTest extends OrmTestCase
21
{
22
    abstract protected function _loadDriver();
23
24
    public function createClassMetadata($entityClassName)
25
    {
26
        $mappingDriver = $this->_loadDriver();
27
28
        $class = new ClassMetadata($entityClassName);
29
        $class->initializeReflection(new RuntimeReflectionService());
30
        $mappingDriver->loadMetadataForClass($entityClassName, $class);
31
32
        return $class;
33
    }
34
35
    /**
36
     * @param \Doctrine\ORM\EntityManager $entityClassName
0 ignored issues
show
Bug introduced by
There is no parameter named $entityClassName. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
37
     * @return \Doctrine\ORM\Mapping\ClassMetadataFactory
38
     */
39
    protected function createClassMetadataFactory(EntityManager $em = null)
40
    {
41
        $driver     = $this->_loadDriver();
42
        $em         = $em ?: $this->_getTestEntityManager();
43
        $factory    = new ClassMetadataFactory();
44
        $em->getConfiguration()->setMetadataDriverImpl($driver);
45
        $factory->setEntityManager($em);
46
47
        return $factory;
48
    }
49
50
    public function testLoadMapping()
51
    {
52
        $entityClassName = 'Doctrine\Tests\ORM\Mapping\User';
53
        return $this->createClassMetadata($entityClassName);
54
    }
55
56
    /**
57
     * @depends testLoadMapping
58
     * @param ClassMetadata $class
59
     */
60
    public function testEntityTableNameAndInheritance($class)
61
    {
62
        $this->assertEquals('cms_users', $class->getTableName());
63
        $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $class->inheritanceType);
64
65
        return $class;
66
    }
67
68
    /**
69
     * @depends testEntityTableNameAndInheritance
70
     * @param ClassMetadata $class
71
     */
72
    public function testEntityIndexes($class)
73
    {
74
        $this->assertArrayHasKey('indexes', $class->table, 'ClassMetadata should have indexes key in table property.');
75
        $this->assertEquals(array(
76
            'name_idx' => array('columns' => array('name')),
77
            0 => array('columns' => array('user_email'))
78
        ), $class->table['indexes']);
79
80
        return $class;
81
    }
82
83
    public function testEntityIndexFlagsAndPartialIndexes()
84
    {
85
        $class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\Comment');
86
87
        $this->assertEquals(array(
88
            0 => array(
89
                'columns' => array('content'),
90
                'flags' => array('fulltext'),
91
                'options' => array('where' => 'content IS NOT NULL'),
92
            )
93
        ), $class->table['indexes']);
94
    }
95
96
    /**
97
     * @depends testEntityTableNameAndInheritance
98
     * @param ClassMetadata $class
99
     */
100
    public function testEntityUniqueConstraints($class)
101
    {
102
        $this->assertArrayHasKey('uniqueConstraints', $class->table,
103
            'ClassMetadata should have uniqueConstraints key in table property when Unique Constraints are set.');
104
105
        $this->assertEquals(array(
106
            "search_idx" => array("columns" => array("name", "user_email"), 'options' => array('where' => 'name IS NOT NULL'))
107
        ), $class->table['uniqueConstraints']);
108
109
        return $class;
110
    }
111
112
    /**
113
     * @depends testEntityTableNameAndInheritance
114
     * @param ClassMetadata $class
115
     */
116
    public function testEntityOptions($class)
117
    {
118
        $this->assertArrayHasKey('options', $class->table, 'ClassMetadata should have options key in table property.');
119
120
        $this->assertEquals(array(
121
            'foo' => 'bar', 'baz' => array('key' => 'val')
122
        ), $class->table['options']);
123
124
        return $class;
125
    }
126
127
    /**
128
     * @depends testEntityOptions
129
     * @param ClassMetadata $class
130
     */
131
    public function testEntitySequence($class)
132
    {
133
        $this->assertInternalType('array', $class->sequenceGeneratorDefinition, 'No Sequence Definition set on this driver.');
134
        $this->assertEquals(
135
            array(
136
                'sequenceName' => 'tablename_seq',
137
                'allocationSize' => 100,
138
                'initialValue' => 1,
139
            ),
140
            $class->sequenceGeneratorDefinition
141
        );
142
    }
143
144
    public function testEntityCustomGenerator()
145
    {
146
        $class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\Animal');
147
148
        $this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM,
149
            $class->generatorType, "Generator Type");
150
        $this->assertEquals(
151
            array("class" => "stdClass"),
152
            $class->customGeneratorDefinition,
153
            "Custom Generator Definition");
154
    }
155
156
157
    /**
158
     * @depends testEntityTableNameAndInheritance
159
     * @param ClassMetadata $class
160
     */
161
    public function testFieldMappings($class)
162
    {
163
        $this->assertEquals(4, count($class->fieldMappings));
164
        $this->assertTrue(isset($class->fieldMappings['id']));
165
        $this->assertTrue(isset($class->fieldMappings['name']));
166
        $this->assertTrue(isset($class->fieldMappings['email']));
167
        $this->assertTrue(isset($class->fieldMappings['version']));
168
169
        return $class;
170
    }
171
172
    /**
173
     * @depends testFieldMappings
174
     * @param ClassMetadata $class
175
     */
176
    public function testVersionedField($class)
177
    {
178
        $this->assertTrue($class->isVersioned);
179
        $this->assertEquals("version", $class->versionField);
180
181
        $this->assertFalse(isset($class->fieldMappings['version']['version']));
182
    }
183
184
    /**
185
     * @depends testEntityTableNameAndInheritance
186
     * @param ClassMetadata $class
187
     */
188
    public function testFieldMappingsColumnNames($class)
189
    {
190
        $this->assertEquals("id", $class->fieldMappings['id']['columnName']);
191
        $this->assertEquals("name", $class->fieldMappings['name']['columnName']);
192
        $this->assertEquals("user_email", $class->fieldMappings['email']['columnName']);
193
194
        return $class;
195
    }
196
197
    /**
198
     * @depends testEntityTableNameAndInheritance
199
     * @param ClassMetadata $class
200
     */
201
    public function testStringFieldMappings($class)
202
    {
203
        $this->assertEquals('string', $class->fieldMappings['name']['type']);
204
        $this->assertEquals(50, $class->fieldMappings['name']['length']);
205
        $this->assertTrue($class->fieldMappings['name']['nullable']);
206
        $this->assertTrue($class->fieldMappings['name']['unique']);
207
208
        return $class;
209
    }
210
211
    /**
212
     * @depends testEntityTableNameAndInheritance
213
     * @param ClassMetadata $class
214
     */
215
    public function testFieldOptions($class)
216
    {
217
        $expected = array('foo' => 'bar', 'baz' => array('key' => 'val'));
218
        $this->assertEquals($expected, $class->fieldMappings['name']['options']);
219
220
        return $class;
221
    }
222
223
    /**
224
     * @depends testEntityTableNameAndInheritance
225
     * @param ClassMetadata $class
226
     */
227
    public function testIdFieldOptions($class)
228
    {
229
        $this->assertEquals(array('foo' => 'bar'), $class->fieldMappings['id']['options']);
230
231
        return $class;
232
    }
233
234
    /**
235
     * @depends testFieldMappings
236
     * @param ClassMetadata $class
237
     */
238
    public function testIdentifier($class)
239
    {
240
        $this->assertEquals(array('id'), $class->identifier);
241
        $this->assertEquals('integer', $class->fieldMappings['id']['type']);
242
        $this->assertEquals(ClassMetadata::GENERATOR_TYPE_AUTO, $class->generatorType, "ID-Generator is not ClassMetadata::GENERATOR_TYPE_AUTO");
243
244
        return $class;
245
    }
246
247
    /**
248
     * @depends testIdentifier
249
     * @param ClassMetadata $class
250
     */
251
    public function testAssociations($class)
252
    {
253
        $this->assertEquals(3, count($class->associationMappings));
254
255
        return $class;
256
    }
257
258
    /**
259
     * @depends testAssociations
260
     * @param ClassMetadata $class
261
     */
262
    public function testOwningOneToOneAssociation($class)
263
    {
264
        $this->assertTrue(isset($class->associationMappings['address']));
265
        $this->assertTrue($class->associationMappings['address']['isOwningSide']);
266
        $this->assertEquals('user', $class->associationMappings['address']['inversedBy']);
267
        // Check cascading
268
        $this->assertTrue($class->associationMappings['address']['isCascadeRemove']);
269
        $this->assertFalse($class->associationMappings['address']['isCascadePersist']);
270
        $this->assertFalse($class->associationMappings['address']['isCascadeRefresh']);
271
        $this->assertFalse($class->associationMappings['address']['isCascadeDetach']);
272
        $this->assertFalse($class->associationMappings['address']['isCascadeMerge']);
273
274
        return $class;
275
    }
276
277
    /**
278
     * @depends testOwningOneToOneAssociation
279
     * @param ClassMetadata $class
280
     */
281
    public function testInverseOneToManyAssociation($class)
282
    {
283
        $this->assertTrue(isset($class->associationMappings['phonenumbers']));
284
        $this->assertFalse($class->associationMappings['phonenumbers']['isOwningSide']);
285
        $this->assertTrue($class->associationMappings['phonenumbers']['isCascadePersist']);
286
        $this->assertTrue($class->associationMappings['phonenumbers']['isCascadeRemove']);
287
        $this->assertFalse($class->associationMappings['phonenumbers']['isCascadeRefresh']);
288
        $this->assertFalse($class->associationMappings['phonenumbers']['isCascadeDetach']);
289
        $this->assertFalse($class->associationMappings['phonenumbers']['isCascadeMerge']);
290
        $this->assertTrue($class->associationMappings['phonenumbers']['orphanRemoval']);
291
292
        // Test Order By
293
        $this->assertEquals(array('number' => 'ASC'), $class->associationMappings['phonenumbers']['orderBy']);
294
295
        return $class;
296
    }
297
298
    /**
299
     * @depends testInverseOneToManyAssociation
300
     * @param ClassMetadata $class
301
     */
302
    public function testManyToManyAssociationWithCascadeAll($class)
303
    {
304
        $this->assertTrue(isset($class->associationMappings['groups']));
305
        $this->assertTrue($class->associationMappings['groups']['isOwningSide']);
306
        // Make sure that cascade-all works as expected
307
        $this->assertTrue($class->associationMappings['groups']['isCascadeRemove']);
308
        $this->assertTrue($class->associationMappings['groups']['isCascadePersist']);
309
        $this->assertTrue($class->associationMappings['groups']['isCascadeRefresh']);
310
        $this->assertTrue($class->associationMappings['groups']['isCascadeDetach']);
311
        $this->assertTrue($class->associationMappings['groups']['isCascadeMerge']);
312
313
        $this->assertFalse(isset($class->associationMappings['groups']['orderBy']));
314
315
        return $class;
316
    }
317
318
    /**
319
     * @depends testManyToManyAssociationWithCascadeAll
320
     * @param ClassMetadata $class
321
     */
322
    public function testLifecycleCallbacks($class)
323
    {
324
        $this->assertEquals(count($class->lifecycleCallbacks), 2);
325
        $this->assertEquals($class->lifecycleCallbacks['prePersist'][0], 'doStuffOnPrePersist');
326
        $this->assertEquals($class->lifecycleCallbacks['postPersist'][0], 'doStuffOnPostPersist');
327
328
        return $class;
329
    }
330
331
    /**
332
     * @depends testManyToManyAssociationWithCascadeAll
333
     * @param ClassMetadata $class
334
     */
335
    public function testLifecycleCallbacksSupportMultipleMethodNames($class)
336
    {
337
        $this->assertEquals(count($class->lifecycleCallbacks['prePersist']), 2);
338
        $this->assertEquals($class->lifecycleCallbacks['prePersist'][1], 'doOtherStuffOnPrePersistToo');
339
340
        return $class;
341
    }
342
343
    /**
344
     * @depends testLifecycleCallbacksSupportMultipleMethodNames
345
     * @param ClassMetadata $class
346
     */
347
    public function testJoinColumnUniqueAndNullable($class)
348
    {
349
        // Non-Nullability of Join Column
350
        $this->assertFalse($class->associationMappings['groups']['joinTable']['joinColumns'][0]['nullable']);
351
        $this->assertFalse($class->associationMappings['groups']['joinTable']['joinColumns'][0]['unique']);
352
353
        return $class;
354
    }
355
356
    /**
357
     * @depends testJoinColumnUniqueAndNullable
358
     * @param ClassMetadata $class
359
     */
360
    public function testColumnDefinition($class)
361
    {
362
        $this->assertEquals("CHAR(32) NOT NULL", $class->fieldMappings['email']['columnDefinition']);
363
        $this->assertEquals("INT NULL", $class->associationMappings['groups']['joinTable']['inverseJoinColumns'][0]['columnDefinition']);
364
365
        return $class;
366
    }
367
368
    /**
369
     * @depends testColumnDefinition
370
     * @param ClassMetadata $class
371
     */
372
    public function testJoinColumnOnDelete($class)
373
    {
374
        $this->assertEquals('CASCADE', $class->associationMappings['address']['joinColumns'][0]['onDelete']);
375
376
        return $class;
377
    }
378
379
    /**
380
     * @group DDC-514
381
     */
382
    public function testDiscriminatorColumnDefaults()
383
    {
384
        if (strpos(get_class($this), 'PHPMappingDriver') !== false) {
385
            $this->markTestSkipped('PHP Mapping Drivers have no defaults.');
386
        }
387
388
        $class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\Animal');
389
390
        $this->assertEquals(
391
            array('name' => 'discr', 'type' => 'string', 'length' => '32', 'fieldName' => 'discr', 'columnDefinition' => null),
392
            $class->discriminatorColumn
393
        );
394
    }
395
396
    /**
397
     * @group DDC-869
398
     */
399
    public function testMappedSuperclassWithRepository()
400
    {
401
        $em         = $this->_getTestEntityManager();
402
        $factory    = $this->createClassMetadataFactory($em);
403
404
405
        $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment');
406
407
        $this->assertTrue(isset($class->fieldMappings['id']));
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
408
        $this->assertTrue(isset($class->fieldMappings['value']));
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
409
        $this->assertTrue(isset($class->fieldMappings['creditCardNumber']));
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
410
        $this->assertEquals($class->customRepositoryClassName, "Doctrine\Tests\Models\DDC869\DDC869PaymentRepository");
0 ignored issues
show
Bug introduced by
Accessing customRepositoryClassName on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
411
        $this->assertInstanceOf("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository",
412
             $em->getRepository("Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment"));
413
        $this->assertTrue($em->getRepository("Doctrine\Tests\Models\DDC869\DDC869ChequePayment")->isTrue());
0 ignored issues
show
Documentation Bug introduced by
The method isTrue does not exist on object<Doctrine\ORM\EntityRepository>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
414
415
416
417
        $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869ChequePayment');
418
419
        $this->assertTrue(isset($class->fieldMappings['id']));
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
420
        $this->assertTrue(isset($class->fieldMappings['value']));
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
421
        $this->assertTrue(isset($class->fieldMappings['serialNumber']));
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
422
        $this->assertEquals($class->customRepositoryClassName, "Doctrine\Tests\Models\DDC869\DDC869PaymentRepository");
0 ignored issues
show
Bug introduced by
Accessing customRepositoryClassName on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
423
        $this->assertInstanceOf("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository",
424
             $em->getRepository("Doctrine\Tests\Models\DDC869\DDC869ChequePayment"));
425
        $this->assertTrue($em->getRepository("Doctrine\Tests\Models\DDC869\DDC869ChequePayment")->isTrue());
0 ignored issues
show
Documentation Bug introduced by
The method isTrue does not exist on object<Doctrine\ORM\EntityRepository>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
426
    }
427
428
    /**
429
     * @group DDC-1476
430
     */
431
    public function testDefaultFieldType()
432
    {
433
        $factory    = $this->createClassMetadataFactory();
434
        $class      = $factory->getMetadataFor('Doctrine\Tests\Models\DDC1476\DDC1476EntityWithDefaultFieldType');
435
436
437
        $this->assertArrayHasKey('id', $class->fieldMappings);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
438
        $this->assertArrayHasKey('name', $class->fieldMappings);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
439
440
441
        $this->assertArrayHasKey('type', $class->fieldMappings['id']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
442
        $this->assertArrayHasKey('type', $class->fieldMappings['name']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
443
444
        $this->assertEquals('string', $class->fieldMappings['id']['type']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
445
        $this->assertEquals('string', $class->fieldMappings['name']['type']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
446
447
448
449
        $this->assertArrayHasKey('fieldName', $class->fieldMappings['id']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
450
        $this->assertArrayHasKey('fieldName', $class->fieldMappings['name']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
451
452
        $this->assertEquals('id', $class->fieldMappings['id']['fieldName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
453
        $this->assertEquals('name', $class->fieldMappings['name']['fieldName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
454
455
456
457
        $this->assertArrayHasKey('columnName', $class->fieldMappings['id']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
458
        $this->assertArrayHasKey('columnName', $class->fieldMappings['name']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
459
460
        $this->assertEquals('id', $class->fieldMappings['id']['columnName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
461
        $this->assertEquals('name', $class->fieldMappings['name']['columnName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
462
463
        $this->assertEquals(ClassMetadataInfo::GENERATOR_TYPE_NONE, $class->generatorType);
0 ignored issues
show
Bug introduced by
Accessing generatorType on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
464
    }
465
466
    /**
467
     * @group DDC-1170
468
     */
469
    public function testIdentifierColumnDefinition()
470
    {
471
        $class = $this->createClassMetadata(__NAMESPACE__ . '\DDC1170Entity');
472
473
474
        $this->assertArrayHasKey('id', $class->fieldMappings);
475
        $this->assertArrayHasKey('value', $class->fieldMappings);
476
477
        $this->assertArrayHasKey('columnDefinition', $class->fieldMappings['id']);
478
        $this->assertArrayHasKey('columnDefinition', $class->fieldMappings['value']);
479
480
        $this->assertEquals("INT unsigned NOT NULL", $class->fieldMappings['id']['columnDefinition']);
481
        $this->assertEquals("VARCHAR(255) NOT NULL", $class->fieldMappings['value']['columnDefinition']);
482
    }
483
484
    /**
485
     * @group DDC-559
486
     */
487
    public function testNamingStrategy()
488
    {
489
        $em         = $this->_getTestEntityManager();
490
        $factory    = $this->createClassMetadataFactory($em);
491
492
493
        $this->assertInstanceOf('Doctrine\ORM\Mapping\DefaultNamingStrategy', $em->getConfiguration()->getNamingStrategy());
494
        $em->getConfiguration()->setNamingStrategy(new UnderscoreNamingStrategy(CASE_UPPER));
495
        $this->assertInstanceOf('Doctrine\ORM\Mapping\UnderscoreNamingStrategy', $em->getConfiguration()->getNamingStrategy());
496
497
        $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC1476\DDC1476EntityWithDefaultFieldType');
498
499
        $this->assertEquals('ID', $class->getColumnName('id'));
500
        $this->assertEquals('NAME', $class->getColumnName('name'));
501
        $this->assertEquals('DDC1476ENTITY_WITH_DEFAULT_FIELD_TYPE', $class->table['name']);
0 ignored issues
show
Bug introduced by
Accessing table on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
502
    }
503
504
    /**
505
     * @group DDC-807
506
     * @group DDC-553
507
     */
508
    public function testDiscriminatorColumnDefinition()
509
    {
510
        $class = $this->createClassMetadata(__NAMESPACE__ . '\DDC807Entity');
511
512
        $this->assertArrayHasKey('columnDefinition', $class->discriminatorColumn);
513
        $this->assertArrayHasKey('name', $class->discriminatorColumn);
514
515
        $this->assertEquals("ENUM('ONE','TWO')", $class->discriminatorColumn['columnDefinition']);
516
        $this->assertEquals("dtype", $class->discriminatorColumn['name']);
517
    }
518
519
    /**
520
     * @group DDC-889
521
     */
522
    public function testInvalidEntityOrMappedSuperClassShouldMentionParentClasses()
523
    {
524
        $this->expectException(MappingException::class);
525
        $this->expectExceptionMessage('Class "Doctrine\Tests\Models\DDC889\DDC889Class" sub class of "Doctrine\Tests\Models\DDC889\DDC889SuperClass" is not a valid entity or mapped super class.');
526
527
        $this->createClassMetadata('Doctrine\Tests\Models\DDC889\DDC889Class');
528
    }
529
530
    /**
531
     * @group DDC-889
532
     */
533
    public function testIdentifierRequiredShouldMentionParentClasses()
534
    {
535
        $factory = $this->createClassMetadataFactory();
536
537
        $this->expectException(MappingException::class);
538
        $this->expectExceptionMessage('No identifier/primary key specified for Entity "Doctrine\Tests\Models\DDC889\DDC889Entity" sub class of "Doctrine\Tests\Models\DDC889\DDC889SuperClass". Every Entity must have an identifier/primary key.');
539
540
        $factory->getMetadataFor('Doctrine\Tests\Models\DDC889\DDC889Entity');
541
    }
542
543
    public function testNamedQuery()
544
    {
545
        $driver = $this->_loadDriver();
546
        $class = $this->createClassMetadata(__NAMESPACE__.'\User');
547
548
        $this->assertCount(1, $class->getNamedQueries(), sprintf("Named queries not processed correctly by driver %s", get_class($driver)));
549
    }
550
551
    /**
552
     * @group DDC-1663
553
     */
554
    public function testNamedNativeQuery()
555
    {
556
557
        $class = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress');
558
559
        //named native query
560
        $this->assertCount(3, $class->namedNativeQueries);
561
        $this->assertArrayHasKey('find-all', $class->namedNativeQueries);
562
        $this->assertArrayHasKey('find-by-id', $class->namedNativeQueries);
563
564
565
        $findAllQuery = $class->getNamedNativeQuery('find-all');
566
        $this->assertEquals('find-all', $findAllQuery['name']);
567
        $this->assertEquals('mapping-find-all', $findAllQuery['resultSetMapping']);
568
        $this->assertEquals('SELECT id, country, city FROM cms_addresses', $findAllQuery['query']);
569
570
        $findByIdQuery = $class->getNamedNativeQuery('find-by-id');
571
        $this->assertEquals('find-by-id', $findByIdQuery['name']);
572
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress',$findByIdQuery['resultClass']);
573
        $this->assertEquals('SELECT * FROM cms_addresses WHERE id = ?',  $findByIdQuery['query']);
574
575
        $countQuery = $class->getNamedNativeQuery('count');
576
        $this->assertEquals('count', $countQuery['name']);
577
        $this->assertEquals('mapping-count', $countQuery['resultSetMapping']);
578
        $this->assertEquals('SELECT COUNT(*) AS count FROM cms_addresses',  $countQuery['query']);
579
580
        // result set mapping
581
        $this->assertCount(3, $class->sqlResultSetMappings);
582
        $this->assertArrayHasKey('mapping-count', $class->sqlResultSetMappings);
583
        $this->assertArrayHasKey('mapping-find-all', $class->sqlResultSetMappings);
584
        $this->assertArrayHasKey('mapping-without-fields', $class->sqlResultSetMappings);
585
586
        $findAllMapping = $class->getSqlResultSetMapping('mapping-find-all');
587
        $this->assertEquals('mapping-find-all', $findAllMapping['name']);
588
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress', $findAllMapping['entities'][0]['entityClass']);
589
        $this->assertEquals(array('name'=>'id','column'=>'id'), $findAllMapping['entities'][0]['fields'][0]);
590
        $this->assertEquals(array('name'=>'city','column'=>'city'), $findAllMapping['entities'][0]['fields'][1]);
591
        $this->assertEquals(array('name'=>'country','column'=>'country'), $findAllMapping['entities'][0]['fields'][2]);
592
593
        $withoutFieldsMapping = $class->getSqlResultSetMapping('mapping-without-fields');
594
        $this->assertEquals('mapping-without-fields', $withoutFieldsMapping['name']);
595
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress', $withoutFieldsMapping['entities'][0]['entityClass']);
596
        $this->assertEquals(array(), $withoutFieldsMapping['entities'][0]['fields']);
597
598
        $countMapping = $class->getSqlResultSetMapping('mapping-count');
599
        $this->assertEquals('mapping-count', $countMapping['name']);
600
        $this->assertEquals(array('name'=>'count'), $countMapping['columns'][0]);
601
602
    }
603
604
    /**
605
     * @group DDC-1663
606
     */
607
    public function testSqlResultSetMapping()
608
    {
609
610
        $userMetadata   = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
611
        $personMetadata = $this->createClassMetadata('Doctrine\Tests\Models\Company\CompanyPerson');
612
613
        // user asserts
614
        $this->assertCount(4, $userMetadata->getSqlResultSetMappings());
615
616
        $mapping = $userMetadata->getSqlResultSetMapping('mappingJoinedAddress');
617
        $this->assertEquals(array(),$mapping['columns']);
618
        $this->assertEquals('mappingJoinedAddress', $mapping['name']);
619
        $this->assertNull($mapping['entities'][0]['discriminatorColumn']);
620
        $this->assertEquals(array('name'=>'id','column'=>'id'),                     $mapping['entities'][0]['fields'][0]);
621
        $this->assertEquals(array('name'=>'name','column'=>'name'),                 $mapping['entities'][0]['fields'][1]);
622
        $this->assertEquals(array('name'=>'status','column'=>'status'),             $mapping['entities'][0]['fields'][2]);
623
        $this->assertEquals(array('name'=>'address.zip','column'=>'zip'),           $mapping['entities'][0]['fields'][3]);
624
        $this->assertEquals(array('name'=>'address.city','column'=>'city'),         $mapping['entities'][0]['fields'][4]);
625
        $this->assertEquals(array('name'=>'address.country','column'=>'country'),   $mapping['entities'][0]['fields'][5]);
626
        $this->assertEquals(array('name'=>'address.id','column'=>'a_id'),           $mapping['entities'][0]['fields'][6]);
627
        $this->assertEquals($userMetadata->name,                                    $mapping['entities'][0]['entityClass']);
628
629
630
        $mapping = $userMetadata->getSqlResultSetMapping('mappingJoinedPhonenumber');
631
        $this->assertEquals(array(),$mapping['columns']);
632
        $this->assertEquals('mappingJoinedPhonenumber', $mapping['name']);
633
        $this->assertNull($mapping['entities'][0]['discriminatorColumn']);
634
        $this->assertEquals(array('name'=>'id','column'=>'id'),                             $mapping['entities'][0]['fields'][0]);
635
        $this->assertEquals(array('name'=>'name','column'=>'name'),                         $mapping['entities'][0]['fields'][1]);
636
        $this->assertEquals(array('name'=>'status','column'=>'status'),                     $mapping['entities'][0]['fields'][2]);
637
        $this->assertEquals(array('name'=>'phonenumbers.phonenumber','column'=>'number'),   $mapping['entities'][0]['fields'][3]);
638
        $this->assertEquals($userMetadata->name,                                            $mapping['entities'][0]['entityClass']);
639
640
        $mapping = $userMetadata->getSqlResultSetMapping('mappingUserPhonenumberCount');
641
        $this->assertEquals(array('name'=>'numphones'),$mapping['columns'][0]);
642
        $this->assertEquals('mappingUserPhonenumberCount', $mapping['name']);
643
        $this->assertNull($mapping['entities'][0]['discriminatorColumn']);
644
        $this->assertEquals(array('name'=>'id','column'=>'id'),         $mapping['entities'][0]['fields'][0]);
645
        $this->assertEquals(array('name'=>'name','column'=>'name'),     $mapping['entities'][0]['fields'][1]);
646
        $this->assertEquals(array('name'=>'status','column'=>'status'), $mapping['entities'][0]['fields'][2]);
647
        $this->assertEquals($userMetadata->name,                        $mapping['entities'][0]['entityClass']);
648
649
        $mapping = $userMetadata->getSqlResultSetMapping('mappingMultipleJoinsEntityResults');
650
        $this->assertEquals(array('name'=>'numphones'),$mapping['columns'][0]);
651
        $this->assertEquals('mappingMultipleJoinsEntityResults', $mapping['name']);
652
        $this->assertNull($mapping['entities'][0]['discriminatorColumn']);
653
        $this->assertEquals(array('name'=>'id','column'=>'u_id'),           $mapping['entities'][0]['fields'][0]);
654
        $this->assertEquals(array('name'=>'name','column'=>'u_name'),       $mapping['entities'][0]['fields'][1]);
655
        $this->assertEquals(array('name'=>'status','column'=>'u_status'),   $mapping['entities'][0]['fields'][2]);
656
        $this->assertEquals($userMetadata->name,                            $mapping['entities'][0]['entityClass']);
657
        $this->assertNull($mapping['entities'][1]['discriminatorColumn']);
658
        $this->assertEquals(array('name'=>'id','column'=>'a_id'),           $mapping['entities'][1]['fields'][0]);
659
        $this->assertEquals(array('name'=>'zip','column'=>'a_zip'),         $mapping['entities'][1]['fields'][1]);
660
        $this->assertEquals(array('name'=>'country','column'=>'a_country'), $mapping['entities'][1]['fields'][2]);
661
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress',         $mapping['entities'][1]['entityClass']);
662
663
        //person asserts
664
        $this->assertCount(1, $personMetadata->getSqlResultSetMappings());
665
666
        $mapping = $personMetadata->getSqlResultSetMapping('mappingFetchAll');
667
        $this->assertEquals(array(),$mapping['columns']);
668
        $this->assertEquals('mappingFetchAll', $mapping['name']);
669
        $this->assertEquals('discriminator',                            $mapping['entities'][0]['discriminatorColumn']);
670
        $this->assertEquals(array('name'=>'id','column'=>'id'),         $mapping['entities'][0]['fields'][0]);
671
        $this->assertEquals(array('name'=>'name','column'=>'name'),     $mapping['entities'][0]['fields'][1]);
672
        $this->assertEquals($personMetadata->name,                      $mapping['entities'][0]['entityClass']);
673
    }
674
675
    /*
676
     * @group DDC-964
677
     */
678
    public function testAssociationOverridesMapping()
679
    {
680
681
        $factory        = $this->createClassMetadataFactory();
682
        $adminMetadata  = $factory->getMetadataFor('Doctrine\Tests\Models\DDC964\DDC964Admin');
683
        $guestMetadata  = $factory->getMetadataFor('Doctrine\Tests\Models\DDC964\DDC964Guest');
684
685
686
        // assert groups association mappings
687
        $this->assertArrayHasKey('groups', $guestMetadata->associationMappings);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
688
        $this->assertArrayHasKey('groups', $adminMetadata->associationMappings);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
689
690
        $guestGroups = $guestMetadata->associationMappings['groups'];
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
691
        $adminGroups = $adminMetadata->associationMappings['groups'];
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
692
693
        // assert not override attributes
694
        $this->assertEquals($guestGroups['fieldName'], $adminGroups['fieldName']);
695
        $this->assertEquals($guestGroups['type'], $adminGroups['type']);
696
        $this->assertEquals($guestGroups['mappedBy'], $adminGroups['mappedBy']);
697
        $this->assertEquals($guestGroups['inversedBy'], $adminGroups['inversedBy']);
698
        $this->assertEquals($guestGroups['isOwningSide'], $adminGroups['isOwningSide']);
699
        $this->assertEquals($guestGroups['fetch'], $adminGroups['fetch']);
700
        $this->assertEquals($guestGroups['isCascadeRemove'], $adminGroups['isCascadeRemove']);
701
        $this->assertEquals($guestGroups['isCascadePersist'], $adminGroups['isCascadePersist']);
702
        $this->assertEquals($guestGroups['isCascadeRefresh'], $adminGroups['isCascadeRefresh']);
703
        $this->assertEquals($guestGroups['isCascadeMerge'], $adminGroups['isCascadeMerge']);
704
        $this->assertEquals($guestGroups['isCascadeDetach'], $adminGroups['isCascadeDetach']);
705
706
         // assert not override attributes
707
        $this->assertEquals('ddc964_users_groups', $guestGroups['joinTable']['name']);
708
        $this->assertEquals('user_id', $guestGroups['joinTable']['joinColumns'][0]['name']);
709
        $this->assertEquals('group_id', $guestGroups['joinTable']['inverseJoinColumns'][0]['name']);
710
711
        $this->assertEquals(array('user_id'=>'id'), $guestGroups['relationToSourceKeyColumns']);
712
        $this->assertEquals(array('group_id'=>'id'), $guestGroups['relationToTargetKeyColumns']);
713
        $this->assertEquals(array('user_id','group_id'), $guestGroups['joinTableColumns']);
714
715
716
        $this->assertEquals('ddc964_users_admingroups', $adminGroups['joinTable']['name']);
717
        $this->assertEquals('adminuser_id', $adminGroups['joinTable']['joinColumns'][0]['name']);
718
        $this->assertEquals('admingroup_id', $adminGroups['joinTable']['inverseJoinColumns'][0]['name']);
719
720
        $this->assertEquals(array('adminuser_id'=>'id'), $adminGroups['relationToSourceKeyColumns']);
721
        $this->assertEquals(array('admingroup_id'=>'id'), $adminGroups['relationToTargetKeyColumns']);
722
        $this->assertEquals(array('adminuser_id','admingroup_id'), $adminGroups['joinTableColumns']);
723
724
725
        // assert address association mappings
726
        $this->assertArrayHasKey('address', $guestMetadata->associationMappings);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
727
        $this->assertArrayHasKey('address', $adminMetadata->associationMappings);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
728
729
        $guestAddress = $guestMetadata->associationMappings['address'];
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
730
        $adminAddress = $adminMetadata->associationMappings['address'];
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
731
732
        // assert not override attributes
733
        $this->assertEquals($guestAddress['fieldName'], $adminAddress['fieldName']);
734
        $this->assertEquals($guestAddress['type'], $adminAddress['type']);
735
        $this->assertEquals($guestAddress['mappedBy'], $adminAddress['mappedBy']);
736
        $this->assertEquals($guestAddress['inversedBy'], $adminAddress['inversedBy']);
737
        $this->assertEquals($guestAddress['isOwningSide'], $adminAddress['isOwningSide']);
738
        $this->assertEquals($guestAddress['fetch'], $adminAddress['fetch']);
739
        $this->assertEquals($guestAddress['isCascadeRemove'], $adminAddress['isCascadeRemove']);
740
        $this->assertEquals($guestAddress['isCascadePersist'], $adminAddress['isCascadePersist']);
741
        $this->assertEquals($guestAddress['isCascadeRefresh'], $adminAddress['isCascadeRefresh']);
742
        $this->assertEquals($guestAddress['isCascadeMerge'], $adminAddress['isCascadeMerge']);
743
        $this->assertEquals($guestAddress['isCascadeDetach'], $adminAddress['isCascadeDetach']);
744
745
        // assert override
746
        $this->assertEquals('address_id', $guestAddress['joinColumns'][0]['name']);
747
        $this->assertEquals(array('address_id'=>'id'), $guestAddress['sourceToTargetKeyColumns']);
748
        $this->assertEquals(array('address_id'=>'address_id'), $guestAddress['joinColumnFieldNames']);
749
        $this->assertEquals(array('id'=>'address_id'), $guestAddress['targetToSourceKeyColumns']);
750
751
752
        $this->assertEquals('adminaddress_id', $adminAddress['joinColumns'][0]['name']);
753
        $this->assertEquals(array('adminaddress_id'=>'id'), $adminAddress['sourceToTargetKeyColumns']);
754
        $this->assertEquals(array('adminaddress_id'=>'adminaddress_id'), $adminAddress['joinColumnFieldNames']);
755
        $this->assertEquals(array('id'=>'adminaddress_id'), $adminAddress['targetToSourceKeyColumns']);
756
    }
757
758
    /*
759
     * @group DDC-3579
760
     */
761
    public function testInversedByOverrideMapping()
762
    {
763
764
        $factory        = $this->createClassMetadataFactory();
765
        $adminMetadata  = $factory->getMetadataFor('Doctrine\Tests\Models\DDC3579\DDC3579Admin');
766
767
        // assert groups association mappings
768
        $this->assertArrayHasKey('groups', $adminMetadata->associationMappings);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
769
        $adminGroups = $adminMetadata->associationMappings['groups'];
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
770
771
        // assert override
772
        $this->assertEquals('admins', $adminGroups['inversedBy']);
773
    }
774
775
    /**
776
     * @group DDC-5934
777
     */
778
    public function testFetchOverrideMapping()
779
    {
780
        // check override metadata
781
        $contractMetadata = $this->createClassMetadataFactory()->getMetadataFor('Doctrine\Tests\Models\DDC5934\DDC5934Contract');
782
783
        $this->assertArrayHasKey('members', $contractMetadata->associationMappings);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
784
        $this->assertSame('EXTRA_LAZY', $contractMetadata->associationMappings['members']['fetch']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
785
786
        // check base metadata
787
        $baseMetadata = $this->createClassMetadataFactory()->getMetadataFor('Doctrine\Tests\Models\DDC5934\DDC5934BaseContract');
788
789
        $this->assertArrayHasKey('members', $baseMetadata->associationMappings);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
790
        $this->assertSame('LAZY', $baseMetadata->associationMappings['members']['fetch']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
791
    }
792
793
    /**
794
     * @group DDC-964
795
     */
796
    public function testAttributeOverridesMapping()
797
    {
798
799
        $factory       = $this->createClassMetadataFactory();
800
        $guestMetadata = $factory->getMetadataFor('Doctrine\Tests\Models\DDC964\DDC964Guest');
801
        $adminMetadata = $factory->getMetadataFor('Doctrine\Tests\Models\DDC964\DDC964Admin');
802
803
        $this->assertTrue($adminMetadata->fieldMappings['id']['id']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
804
        $this->assertEquals('id', $adminMetadata->fieldMappings['id']['fieldName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
805
        $this->assertEquals('user_id', $adminMetadata->fieldMappings['id']['columnName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
806
        $this->assertEquals(array('user_id'=>'id','user_name'=>'name'), $adminMetadata->fieldNames);
0 ignored issues
show
Bug introduced by
Accessing fieldNames on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
807
        $this->assertEquals(array('id'=>'user_id','name'=>'user_name'), $adminMetadata->columnNames);
0 ignored issues
show
Bug introduced by
Accessing columnNames on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
808
        $this->assertEquals(150, $adminMetadata->fieldMappings['id']['length']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
809
810
811
        $this->assertEquals('name', $adminMetadata->fieldMappings['name']['fieldName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
812
        $this->assertEquals('user_name', $adminMetadata->fieldMappings['name']['columnName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
813
        $this->assertEquals(250, $adminMetadata->fieldMappings['name']['length']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
814
        $this->assertTrue($adminMetadata->fieldMappings['name']['nullable']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
815
        $this->assertFalse($adminMetadata->fieldMappings['name']['unique']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
816
817
818
        $this->assertTrue($guestMetadata->fieldMappings['id']['id']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
819
        $this->assertEquals('guest_id', $guestMetadata->fieldMappings['id']['columnName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
820
        $this->assertEquals('id', $guestMetadata->fieldMappings['id']['fieldName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
821
        $this->assertEquals(array('guest_id'=>'id','guest_name'=>'name'), $guestMetadata->fieldNames);
0 ignored issues
show
Bug introduced by
Accessing fieldNames on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
822
        $this->assertEquals(array('id'=>'guest_id','name'=>'guest_name'), $guestMetadata->columnNames);
0 ignored issues
show
Bug introduced by
Accessing columnNames on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
823
        $this->assertEquals(140, $guestMetadata->fieldMappings['id']['length']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
824
825
        $this->assertEquals('name', $guestMetadata->fieldMappings['name']['fieldName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
826
        $this->assertEquals('guest_name', $guestMetadata->fieldMappings['name']['columnName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
827
        $this->assertEquals(240, $guestMetadata->fieldMappings['name']['length']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
828
        $this->assertFalse($guestMetadata->fieldMappings['name']['nullable']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
829
        $this->assertTrue($guestMetadata->fieldMappings['name']['unique']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
830
    }
831
832
    /**
833
     * @group DDC-1955
834
     */
835
    public function testEntityListeners()
836
    {
837
        $em         = $this->_getTestEntityManager();
838
        $factory    = $this->createClassMetadataFactory($em);
839
        $superClass = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyContract');
840
        $flexClass  = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyFixContract');
841
        $fixClass   = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyFlexContract');
842
        $ultraClass = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyFlexUltraContract');
0 ignored issues
show
Unused Code introduced by
$ultraClass is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
843
844
        $this->assertArrayHasKey(Events::prePersist, $superClass->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
845
        $this->assertArrayHasKey(Events::postPersist, $superClass->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
846
847
        $this->assertCount(1, $superClass->entityListeners[Events::prePersist]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
848
        $this->assertCount(1, $superClass->entityListeners[Events::postPersist]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
849
850
        $postPersist = $superClass->entityListeners[Events::postPersist][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
851
        $prePersist  = $superClass->entityListeners[Events::prePersist][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
852
853
        $this->assertEquals('Doctrine\Tests\Models\Company\CompanyContractListener', $postPersist['class']);
854
        $this->assertEquals('Doctrine\Tests\Models\Company\CompanyContractListener', $prePersist['class']);
855
        $this->assertEquals('postPersistHandler', $postPersist['method']);
856
        $this->assertEquals('prePersistHandler', $prePersist['method']);
857
858
        //Inherited listeners
859
        $this->assertEquals($fixClass->entityListeners, $superClass->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
860
        $this->assertEquals($flexClass->entityListeners, $superClass->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
861
    }
862
863
    /**
864
     * @group DDC-1955
865
     */
866
    public function testEntityListenersOverride()
867
    {
868
        $em         = $this->_getTestEntityManager();
869
        $factory    = $this->createClassMetadataFactory($em);
870
        $ultraClass = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyFlexUltraContract');
871
872
        //overridden listeners
873
        $this->assertArrayHasKey(Events::postPersist, $ultraClass->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
874
        $this->assertArrayHasKey(Events::prePersist, $ultraClass->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
875
876
        $this->assertCount(1, $ultraClass->entityListeners[Events::postPersist]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
877
        $this->assertCount(3, $ultraClass->entityListeners[Events::prePersist]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
878
879
        $postPersist = $ultraClass->entityListeners[Events::postPersist][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
880
        $prePersist  = $ultraClass->entityListeners[Events::prePersist][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
881
882
        $this->assertEquals('Doctrine\Tests\Models\Company\CompanyContractListener', $postPersist['class']);
883
        $this->assertEquals('Doctrine\Tests\Models\Company\CompanyContractListener', $prePersist['class']);
884
        $this->assertEquals('postPersistHandler', $postPersist['method']);
885
        $this->assertEquals('prePersistHandler', $prePersist['method']);
886
887
        $prePersist = $ultraClass->entityListeners[Events::prePersist][1];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
888
        $this->assertEquals('Doctrine\Tests\Models\Company\CompanyFlexUltraContractListener', $prePersist['class']);
889
        $this->assertEquals('prePersistHandler1', $prePersist['method']);
890
891
        $prePersist = $ultraClass->entityListeners[Events::prePersist][2];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
892
        $this->assertEquals('Doctrine\Tests\Models\Company\CompanyFlexUltraContractListener', $prePersist['class']);
893
        $this->assertEquals('prePersistHandler2', $prePersist['method']);
894
    }
895
896
897
    /**
898
     * @group DDC-1955
899
     */
900
    public function testEntityListenersNamingConvention()
901
    {
902
        $em         = $this->_getTestEntityManager();
903
        $factory    = $this->createClassMetadataFactory($em);
904
        $metadata   = $factory->getMetadataFor('Doctrine\Tests\Models\CMS\CmsAddress');
905
906
        $this->assertArrayHasKey(Events::postPersist, $metadata->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
907
        $this->assertArrayHasKey(Events::prePersist, $metadata->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
908
        $this->assertArrayHasKey(Events::postUpdate, $metadata->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
909
        $this->assertArrayHasKey(Events::preUpdate, $metadata->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
910
        $this->assertArrayHasKey(Events::postRemove, $metadata->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
911
        $this->assertArrayHasKey(Events::preRemove, $metadata->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
912
        $this->assertArrayHasKey(Events::postLoad, $metadata->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
913
        $this->assertArrayHasKey(Events::preFlush, $metadata->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
914
915
        $this->assertCount(1, $metadata->entityListeners[Events::postPersist]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
916
        $this->assertCount(1, $metadata->entityListeners[Events::prePersist]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
917
        $this->assertCount(1, $metadata->entityListeners[Events::postUpdate]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
918
        $this->assertCount(1, $metadata->entityListeners[Events::preUpdate]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
919
        $this->assertCount(1, $metadata->entityListeners[Events::postRemove]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
920
        $this->assertCount(1, $metadata->entityListeners[Events::preRemove]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
921
        $this->assertCount(1, $metadata->entityListeners[Events::postLoad]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
922
        $this->assertCount(1, $metadata->entityListeners[Events::preFlush]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
923
924
        $postPersist = $metadata->entityListeners[Events::postPersist][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
925
        $prePersist  = $metadata->entityListeners[Events::prePersist][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
926
        $postUpdate  = $metadata->entityListeners[Events::postUpdate][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
927
        $preUpdate   = $metadata->entityListeners[Events::preUpdate][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
928
        $postRemove  = $metadata->entityListeners[Events::postRemove][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
929
        $preRemove   = $metadata->entityListeners[Events::preRemove][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
930
        $postLoad    = $metadata->entityListeners[Events::postLoad][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
931
        $preFlush    = $metadata->entityListeners[Events::preFlush][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
932
933
934
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $postPersist['class']);
935
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $prePersist['class']);
936
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $postUpdate['class']);
937
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $preUpdate['class']);
938
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $postRemove['class']);
939
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $preRemove['class']);
940
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $postLoad['class']);
941
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $preFlush['class']);
942
943
        $this->assertEquals(Events::postPersist, $postPersist['method']);
944
        $this->assertEquals(Events::prePersist, $prePersist['method']);
945
        $this->assertEquals(Events::postUpdate, $postUpdate['method']);
946
        $this->assertEquals(Events::preUpdate, $preUpdate['method']);
947
        $this->assertEquals(Events::postRemove, $postRemove['method']);
948
        $this->assertEquals(Events::preRemove, $preRemove['method']);
949
        $this->assertEquals(Events::postLoad, $postLoad['method']);
950
        $this->assertEquals(Events::preFlush, $preFlush['method']);
951
    }
952
953
    /**
954
     * @group DDC-2183
955
     */
956
    public function testSecondLevelCacheMapping()
957
    {
958
        $em      = $this->_getTestEntityManager();
959
        $factory = $this->createClassMetadataFactory($em);
960
        $class   = $factory->getMetadataFor(City::CLASSNAME);
961
        $this->assertArrayHasKey('usage', $class->cache);
0 ignored issues
show
Bug introduced by
Accessing cache on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
962
        $this->assertArrayHasKey('region', $class->cache);
0 ignored issues
show
Bug introduced by
Accessing cache on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
963
        $this->assertEquals(ClassMetadata::CACHE_USAGE_READ_ONLY, $class->cache['usage']);
0 ignored issues
show
Bug introduced by
Accessing cache on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
964
        $this->assertEquals('doctrine_tests_models_cache_city', $class->cache['region']);
0 ignored issues
show
Bug introduced by
Accessing cache on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
965
966
        $this->assertArrayHasKey('state', $class->associationMappings);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
967
        $this->assertArrayHasKey('cache', $class->associationMappings['state']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
968
        $this->assertArrayHasKey('usage', $class->associationMappings['state']['cache']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
969
        $this->assertArrayHasKey('region', $class->associationMappings['state']['cache']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
970
        $this->assertEquals(ClassMetadata::CACHE_USAGE_READ_ONLY, $class->associationMappings['state']['cache']['usage']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
971
        $this->assertEquals('doctrine_tests_models_cache_city__state', $class->associationMappings['state']['cache']['region']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
972
973
        $this->assertArrayHasKey('attractions', $class->associationMappings);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
974
        $this->assertArrayHasKey('cache', $class->associationMappings['attractions']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
975
        $this->assertArrayHasKey('usage', $class->associationMappings['attractions']['cache']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
976
        $this->assertArrayHasKey('region', $class->associationMappings['attractions']['cache']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
977
        $this->assertEquals(ClassMetadata::CACHE_USAGE_READ_ONLY, $class->associationMappings['attractions']['cache']['usage']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
978
        $this->assertEquals('doctrine_tests_models_cache_city__attractions', $class->associationMappings['attractions']['cache']['region']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
979
    }
980
981
    /**
982
     * @group DDC-2825
983
     * @group 881
984
     */
985
    public function testSchemaDefinitionViaExplicitTableSchemaAnnotationProperty()
986
    {
987
        /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */
988
        $metadata = $this->createClassMetadataFactory()->getMetadataFor(ExplicitSchemaAndTable::CLASSNAME);
989
990
        $this->assertSame('explicit_schema', $metadata->getSchemaName());
991
        $this->assertSame('explicit_table', $metadata->getTableName());
992
    }
993
994
    /**
995
     * @group DDC-2825
996
     * @group 881
997
     */
998
    public function testSchemaDefinitionViaSchemaDefinedInTableNameInTableAnnotationProperty()
999
    {
1000
        /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */
1001
        $metadata = $this->createClassMetadataFactory()->getMetadataFor(SchemaAndTableInTableName::CLASSNAME);
1002
1003
        $this->assertSame('implicit_schema', $metadata->getSchemaName());
1004
        $this->assertSame('implicit_table', $metadata->getTableName());
1005
    }
1006
1007
    /**
1008
     * @group DDC-514
1009
     * @group DDC-1015
1010
     */
1011
    public function testDiscriminatorColumnDefaultLength()
1012
    {
1013
        if (strpos(get_class($this), 'PHPMappingDriver') !== false) {
1014
            $this->markTestSkipped('PHP Mapping Drivers have no defaults.');
1015
        }
1016
        $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityNoDiscriminatorColumnMapping');
1017
        $this->assertEquals(255, $class->discriminatorColumn['length']);
1018
        $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityIncompleteDiscriminatorColumnMapping');
1019
        $this->assertEquals(255, $class->discriminatorColumn['length']);
1020
    }
1021
1022
    /**
1023
     * @group DDC-514
1024
     * @group DDC-1015
1025
     */
1026
    public function testDiscriminatorColumnDefaultType()
1027
    {
1028
        if (strpos(get_class($this), 'PHPMappingDriver') !== false) {
1029
            $this->markTestSkipped('PHP Mapping Drivers have no defaults.');
1030
        }
1031
        $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityNoDiscriminatorColumnMapping');
1032
        $this->assertEquals('string', $class->discriminatorColumn['type']);
1033
        $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityIncompleteDiscriminatorColumnMapping');
1034
        $this->assertEquals('string', $class->discriminatorColumn['type']);
1035
    }
1036
1037
    /**
1038
     * @group DDC-514
1039
     * @group DDC-1015
1040
     */
1041
    public function testDiscriminatorColumnDefaultName()
1042
    {
1043
        if (strpos(get_class($this), 'PHPMappingDriver') !== false) {
1044
            $this->markTestSkipped('PHP Mapping Drivers have no defaults.');
1045
        }
1046
        $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityNoDiscriminatorColumnMapping');
1047
        $this->assertEquals('dtype', $class->discriminatorColumn['name']);
1048
        $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityIncompleteDiscriminatorColumnMapping');
1049
        $this->assertEquals('dtype', $class->discriminatorColumn['name']);
1050
    }
1051
1052
}
1053
1054
/**
1055
 * @Entity
1056
 * @HasLifecycleCallbacks
1057
 * @Table(
1058
 *  name="cms_users",
1059
 *  uniqueConstraints={@UniqueConstraint(name="search_idx", columns={"name", "user_email"}, options={"where": "name IS NOT NULL"})},
1060
 *  indexes={@Index(name="name_idx", columns={"name"}), @Index(name="0", columns={"user_email"})},
1061
 *  options={"foo": "bar", "baz": {"key": "val"}}
1062
 * )
1063
 * @NamedQueries({@NamedQuery(name="all", query="SELECT u FROM __CLASS__ u")})
1064
 */
1065
class User
1066
{
1067
    /**
1068
     * @Id
1069
     * @Column(type="integer", options={"foo": "bar"})
1070
     * @generatedValue(strategy="AUTO")
1071
     * @SequenceGenerator(sequenceName="tablename_seq", initialValue=1, allocationSize=100)
1072
     **/
1073
    public $id;
1074
1075
    /**
1076
     * @Column(length=50, nullable=true, unique=true, options={"foo": "bar", "baz": {"key": "val"}})
1077
     */
1078
    public $name;
1079
1080
    /**
1081
     * @Column(name="user_email", columnDefinition="CHAR(32) NOT NULL")
1082
     */
1083
    public $email;
1084
1085
    /**
1086
     * @OneToOne(targetEntity="Address", cascade={"remove"}, inversedBy="user")
1087
     * @JoinColumn(onDelete="CASCADE")
1088
     */
1089
    public $address;
1090
1091
    /**
1092
     * @OneToMany(targetEntity="Phonenumber", mappedBy="user", cascade={"persist"}, orphanRemoval=true)
1093
     * @OrderBy({"number"="ASC"})
1094
     */
1095
    public $phonenumbers;
1096
1097
    /**
1098
     * @ManyToMany(targetEntity="Group", cascade={"all"})
1099
     * @JoinTable(name="cms_user_groups",
1100
     *    joinColumns={@JoinColumn(name="user_id", referencedColumnName="id", nullable=false, unique=false)},
1101
     *    inverseJoinColumns={@JoinColumn(name="group_id", referencedColumnName="id", columnDefinition="INT NULL")}
1102
     * )
1103
     */
1104
    public $groups;
1105
1106
    /**
1107
     * @Column(type="integer")
1108
     * @Version
1109
     */
1110
    public $version;
1111
1112
1113
    /**
1114
     * @PrePersist
1115
     */
1116
    public function doStuffOnPrePersist()
1117
    {
1118
    }
1119
1120
    /**
1121
     * @PrePersist
1122
     */
1123
    public function doOtherStuffOnPrePersistToo() {
1124
    }
1125
1126
    /**
1127
     * @PostPersist
1128
     */
1129
    public function doStuffOnPostPersist()
1130
    {
1131
1132
    }
1133
1134
    public static function loadMetadata(ClassMetadataInfo $metadata)
1135
    {
1136
        $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
1137
        $metadata->setPrimaryTable(array(
1138
           'name' => 'cms_users',
1139
           'options' => array('foo' => 'bar', 'baz' => array('key' => 'val')),
1140
          ));
1141
        $metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT);
1142
        $metadata->addLifecycleCallback('doStuffOnPrePersist', 'prePersist');
1143
        $metadata->addLifecycleCallback('doOtherStuffOnPrePersistToo', 'prePersist');
1144
        $metadata->addLifecycleCallback('doStuffOnPostPersist', 'postPersist');
1145
        $metadata->mapField(array(
1146
           'id' => true,
1147
           'fieldName' => 'id',
1148
           'type' => 'integer',
1149
           'columnName' => 'id',
1150
           'options' => array('foo' => 'bar'),
1151
          ));
1152
        $metadata->mapField(array(
1153
           'fieldName' => 'name',
1154
           'type' => 'string',
1155
           'length' => 50,
1156
           'unique' => true,
1157
           'nullable' => true,
1158
           'columnName' => 'name',
1159
           'options' => array('foo' => 'bar', 'baz' => array('key' => 'val')),
1160
          ));
1161
        $metadata->mapField(array(
1162
           'fieldName' => 'email',
1163
           'type' => 'string',
1164
           'columnName' => 'user_email',
1165
           'columnDefinition' => 'CHAR(32) NOT NULL',
1166
          ));
1167
        $mapping = array('fieldName' => 'version', 'type' => 'integer');
1168
        $metadata->setVersionMapping($mapping);
1169
        $metadata->mapField($mapping);
1170
        $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
1171
        $metadata->mapOneToOne(array(
1172
           'fieldName' => 'address',
1173
           'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Address',
1174
           'cascade' =>
1175
           array(
1176
           0 => 'remove',
1177
           ),
1178
           'mappedBy' => NULL,
1179
           'inversedBy' => 'user',
1180
           'joinColumns' =>
1181
           array(
1182
           0 =>
1183
           array(
1184
            'name' => 'address_id',
1185
            'referencedColumnName' => 'id',
1186
            'onDelete' => 'CASCADE',
1187
           ),
1188
           ),
1189
           'orphanRemoval' => false,
1190
          ));
1191
        $metadata->mapOneToMany(array(
1192
           'fieldName' => 'phonenumbers',
1193
           'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Phonenumber',
1194
           'cascade' =>
1195
           array(
1196
           1 => 'persist',
1197
           ),
1198
           'mappedBy' => 'user',
1199
           'orphanRemoval' => true,
1200
           'orderBy' =>
1201
           array(
1202
           'number' => 'ASC',
1203
           ),
1204
          ));
1205
        $metadata->mapManyToMany(array(
1206
           'fieldName' => 'groups',
1207
           'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Group',
1208
           'cascade' =>
1209
           array(
1210
           0 => 'remove',
1211
           1 => 'persist',
1212
           2 => 'refresh',
1213
           3 => 'merge',
1214
           4 => 'detach',
1215
           ),
1216
           'mappedBy' => NULL,
1217
           'joinTable' =>
1218
           array(
1219
           'name' => 'cms_users_groups',
1220
           'joinColumns' =>
1221
           array(
1222
            0 =>
1223
            array(
1224
            'name' => 'user_id',
1225
            'referencedColumnName' => 'id',
1226
            'unique' => false,
1227
            'nullable' => false,
1228
            ),
1229
           ),
1230
           'inverseJoinColumns' =>
1231
           array(
1232
            0 =>
1233
            array(
1234
            'name' => 'group_id',
1235
            'referencedColumnName' => 'id',
1236
            'columnDefinition' => 'INT NULL',
1237
            ),
1238
           ),
1239
           ),
1240
           'orderBy' => NULL,
1241
          ));
1242
        $metadata->table['uniqueConstraints'] = array(
1243
            'search_idx' => array('columns' => array('name', 'user_email'), 'options'=> array('where' => 'name IS NOT NULL')),
1244
        );
1245
        $metadata->table['indexes'] = array(
1246
            'name_idx' => array('columns' => array('name')), 0 => array('columns' => array('user_email'))
1247
        );
1248
        $metadata->setSequenceGeneratorDefinition(array(
1249
                'sequenceName' => 'tablename_seq',
1250
                'allocationSize' => 100,
1251
                'initialValue' => 1,
1252
            ));
1253
        $metadata->addNamedQuery(array(
1254
                'name' => 'all',
1255
                'query' => 'SELECT u FROM __CLASS__ u'
1256
            ));
1257
    }
1258
}
1259
1260
/**
1261
 * @Entity
1262
 * @InheritanceType("SINGLE_TABLE")
1263
 * @DiscriminatorMap({"cat" = "Cat", "dog" = "Dog"})
1264
 * @DiscriminatorColumn(name="discr", length=32, type="string")
1265
 */
1266
abstract class Animal
1267
{
1268
    /**
1269
     * @Id @Column(type="string") @GeneratedValue(strategy="CUSTOM")
1270
     * @CustomIdGenerator(class="stdClass")
1271
     */
1272
    public $id;
1273
1274
    public static function loadMetadata(ClassMetadataInfo $metadata)
1275
    {
1276
        $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_CUSTOM);
1277
        $metadata->setCustomGeneratorDefinition(array("class" => "stdClass"));
1278
    }
1279
}
1280
1281
/** @Entity */
1282
class Cat extends Animal
1283
{
1284
    public static function loadMetadata(ClassMetadataInfo $metadata)
1285
    {
1286
1287
    }
1288
}
1289
1290
/** @Entity */
1291
class Dog extends Animal
1292
{
1293
    public static function loadMetadata(ClassMetadataInfo $metadata)
1294
    {
1295
1296
    }
1297
}
1298
1299
1300
/**
1301
 * @Entity
1302
 */
1303
class DDC1170Entity
1304
{
1305
1306
    /**
1307
     * @param string $value
1308
     */
1309
    function __construct($value = null)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1310
    {
1311
        $this->value = $value;
1312
    }
1313
1314
    /**
1315
     * @Id
1316
     * @GeneratedValue(strategy="NONE")
1317
     * @Column(type="integer", columnDefinition = "INT unsigned NOT NULL")
1318
     **/
1319
    private $id;
1320
1321
    /**
1322
     * @Column(columnDefinition = "VARCHAR(255) NOT NULL")
1323
     */
1324
    private $value;
1325
1326
    /**
1327
     * @return int
1328
     */
1329
    public function getId()
1330
    {
1331
        return $this->id;
1332
    }
1333
1334
    /**
1335
     * @return string
1336
     */
1337
    public function getValue()
1338
    {
1339
        return $this->value;
1340
    }
1341
1342
    public static function loadMetadata(ClassMetadataInfo $metadata)
1343
    {
1344
        $metadata->mapField(array(
1345
           'id'                 => true,
1346
           'fieldName'          => 'id',
1347
           'columnDefinition'   => 'INT unsigned NOT NULL',
1348
        ));
1349
1350
        $metadata->mapField(array(
1351
            'fieldName'         => 'value',
1352
            'columnDefinition'  => 'VARCHAR(255) NOT NULL'
1353
        ));
1354
1355
        $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE);
1356
    }
1357
1358
}
1359
1360
/**
1361
 * @Entity
1362
 * @InheritanceType("SINGLE_TABLE")
1363
 * @DiscriminatorMap({"ONE" = "DDC807SubClasse1", "TWO" = "DDC807SubClasse2"})
1364
 * @DiscriminatorColumn(name = "dtype", columnDefinition="ENUM('ONE','TWO')")
1365
 */
1366
class DDC807Entity
1367
{
1368
    /**
1369
     * @Id
1370
     * @Column(type="integer")
1371
     * @GeneratedValue(strategy="NONE")
1372
     **/
1373
   public $id;
1374
1375
   public static function loadMetadata(ClassMetadataInfo $metadata)
1376
    {
1377
         $metadata->mapField(array(
1378
           'id'                 => true,
1379
           'fieldName'          => 'id',
1380
        ));
1381
1382
        $metadata->setDiscriminatorColumn(array(
1383
            'name'              => "dtype",
1384
            'type'              => "string",
1385
            'columnDefinition'  => "ENUM('ONE','TWO')"
1386
        ));
1387
1388
        $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE);
1389
    }
1390
}
1391
1392
class DDC807SubClasse1 {}
1393
class DDC807SubClasse2 {}
1394
1395
class Address {}
1396
class Phonenumber {}
1397
class Group {}
1398
1399
/**
1400
 * @Entity
1401
 * @Table(indexes={@Index(columns={"content"}, flags={"fulltext"}, options={"where": "content IS NOT NULL"})})
1402
 */
1403
class Comment
1404
{
1405
    /**
1406
     * @Column(type="text")
1407
     */
1408
    private $content;
1409
1410
    public static function loadMetadata(ClassMetadataInfo $metadata)
1411
    {
1412
        $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
1413
        $metadata->setPrimaryTable(array(
1414
            'indexes' => array(
1415
                array('columns' => array('content'), 'flags' => array('fulltext'), 'options' => array('where' => 'content IS NOT NULL'))
1416
            )
1417
        ));
1418
1419
        $metadata->mapField(array(
1420
            'fieldName' => 'content',
1421
            'type' => 'text',
1422
            'scale' => 0,
1423
            'length' => NULL,
1424
            'unique' => false,
1425
            'nullable' => false,
1426
            'precision' => 0,
1427
            'columnName' => 'content',
1428
        ));
1429
    }
1430
}
1431
1432
/**
1433
 * @Entity
1434
 * @InheritanceType("SINGLE_TABLE")
1435
 * @DiscriminatorMap({
1436
 *     "ONE" = "SingleTableEntityNoDiscriminatorColumnMappingSub1",
1437
 *     "TWO" = "SingleTableEntityNoDiscriminatorColumnMappingSub2"
1438
 * })
1439
 */
1440
class SingleTableEntityNoDiscriminatorColumnMapping
1441
{
1442
    /**
1443
     * @Id
1444
     * @Column(type="integer")
1445
     * @GeneratedValue(strategy="NONE")
1446
     */
1447
    public $id;
1448
1449
    public static function loadMetadata(ClassMetadataInfo $metadata)
1450
    {
1451
        $metadata->mapField(array(
1452
            'id' => true,
1453
            'fieldName' => 'id',
1454
        ));
1455
1456
        $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE);
1457
    }
1458
}
1459
1460
class SingleTableEntityNoDiscriminatorColumnMappingSub1 extends SingleTableEntityNoDiscriminatorColumnMapping {}
1461
class SingleTableEntityNoDiscriminatorColumnMappingSub2 extends SingleTableEntityNoDiscriminatorColumnMapping {}
1462
1463
/**
1464
 * @Entity
1465
 * @InheritanceType("SINGLE_TABLE")
1466
 * @DiscriminatorMap({
1467
 *     "ONE" = "SingleTableEntityIncompleteDiscriminatorColumnMappingSub1",
1468
 *     "TWO" = "SingleTableEntityIncompleteDiscriminatorColumnMappingSub2"
1469
 * })
1470
 * @DiscriminatorColumn(name="dtype")
1471
 */
1472
class SingleTableEntityIncompleteDiscriminatorColumnMapping
1473
{
1474
    /**
1475
     * @Id
1476
     * @Column(type="integer")
1477
     * @GeneratedValue(strategy="NONE")
1478
     */
1479
    public $id;
1480
1481
    public static function loadMetadata(ClassMetadataInfo $metadata)
1482
    {
1483
        $metadata->mapField(array(
1484
            'id' => true,
1485
            'fieldName' => 'id',
1486
        ));
1487
1488
        $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE);
1489
    }
1490
}
1491
1492
class SingleTableEntityIncompleteDiscriminatorColumnMappingSub1
1493
    extends SingleTableEntityIncompleteDiscriminatorColumnMapping {}
1494
class SingleTableEntityIncompleteDiscriminatorColumnMappingSub2
1495
    extends SingleTableEntityIncompleteDiscriminatorColumnMapping {}