Completed
Push — master ( 7f16e5...ebe11c )
by Marco
62:50
created

AbstractMappingDriverTest   D

Complexity

Total Complexity 54

Size/Duplication

Total Lines 1012
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8
Metric Value
wmc 54
lcom 1
cbo 8
dl 0
loc 1012
rs 4.9222

50 Methods

Rating   Name   Duplication   Size   Complexity  
_loadDriver() 0 1 ?
A createClassMetadata() 0 10 1
A createClassMetadataFactory() 0 10 2
A testLoadMapping() 0 5 1
A testEntityTableNameAndInheritance() 0 7 1
A testEntityIndexes() 0 10 1
A testEntityIndexFlagsAndPartialIndexes() 0 12 1
A testEntityUniqueConstraints() 0 11 1
A testEntityOptions() 0 10 1
A testEntitySequence() 0 12 1
A testEntityCustomGenerator() 0 11 1
A testFieldMappings() 0 10 1
A testVersionedField() 0 7 1
A testFieldMappingsColumnNames() 0 8 1
A testStringFieldMappings() 0 9 1
A testFieldOptions() 0 7 1
A testIdFieldOptions() 0 6 1
A testIdentifier() 0 8 1
A testAssociations() 0 6 1
A testOwningOneToOneAssociation() 0 14 1
A testInverseOneToManyAssociation() 0 16 1
A testManyToManyAssociationWithCascadeAll() 0 15 1
A testLifecycleCallbacks() 0 8 1
A testLifecycleCallbacksSupportMultipleMethodNames() 0 7 1
A testJoinColumnUniqueAndNullable() 0 8 1
A testColumnDefinition() 0 7 1
A testJoinColumnOnDelete() 0 6 1
A testDiscriminatorColumnDefaults() 0 13 2
B testMappedSuperclassWithRepository() 0 28 1
B testDefaultFieldType() 0 34 1
A testIdentifierColumnDefinition() 0 14 1
A testNamingStrategy() 0 16 1
A testDiscriminatorColumnDefinition() 0 10 1
A testInvalidEntityOrMappedSuperClassShouldMentionParentClasses() 0 6 1
A testIdentifierRequiredShouldMentionParentClasses() 0 7 1
A testNamedQuery() 0 7 1
A testNamedNativeQuery() 0 49 1
A testSqlResultSetMapping() 0 67 1
B testAssociationOverridesMapping() 0 79 1
A testInversedByOverrideMapping() 0 13 1
B testAttributeOverridesMapping() 0 35 1
B testEntityListeners() 0 27 1
B testEntityListenersOverride() 0 29 1
A testEntityListenersNamingConvention() 0 52 1
B testSecondLevelCacheMapping() 0 24 1
A testSchemaDefinitionViaExplicitTableSchemaAnnotationProperty() 0 8 1
A testSchemaDefinitionViaSchemaDefinedInTableNameInTableAnnotationProperty() 0 8 1
A testDiscriminatorColumnDefaultLength() 0 10 2
A testDiscriminatorColumnDefaultType() 0 10 2
A testDiscriminatorColumnDefaultName() 0 10 2

How to fix   Complexity   

Complex Class

Complex classes like AbstractMappingDriverTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use AbstractMappingDriverTest, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Doctrine\Tests\ORM\Mapping;
4
5
use Doctrine\ORM\Events;
6
use Doctrine\ORM\Event\LifecycleEventArgs;
7
use Doctrine\ORM\Mapping\DiscriminatorColumn;
8
use Doctrine\ORM\Mapping\Id;
9
use Doctrine\Tests\Models\Company\CompanyFixContract;
10
use Doctrine\Tests\Models\Company\CompanyFlexContract;
11
use Doctrine\Tests\Models\Cache\City;
12
use Doctrine\ORM\Mapping\ClassMetadata;
13
use Doctrine\ORM\Mapping\ClassMetadataInfo;
14
use Doctrine\Tests\Models\DDC2825\ExplicitSchemaAndTable;
15
use Doctrine\Tests\Models\DDC2825\SchemaAndTableInTableName;
16
17
abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
18
{
19
    abstract protected function _loadDriver();
20
21
    public function createClassMetadata($entityClassName)
22
    {
23
        $mappingDriver = $this->_loadDriver();
24
25
        $class = new ClassMetadata($entityClassName);
26
        $class->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
27
        $mappingDriver->loadMetadataForClass($entityClassName, $class);
28
29
        return $class;
30
    }
31
32
    /**
33
     * @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...
34
     * @return \Doctrine\ORM\Mapping\ClassMetadataFactory
35
     */
36
    protected function createClassMetadataFactory(\Doctrine\ORM\EntityManager $em = null)
37
    {
38
        $driver     = $this->_loadDriver();
39
        $em         = $em ?: $this->_getTestEntityManager();
40
        $factory    = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
41
        $em->getConfiguration()->setMetadataDriverImpl($driver);
42
        $factory->setEntityManager($em);
43
44
        return $factory;
45
    }
46
47
    public function testLoadMapping()
48
    {
49
        $entityClassName = 'Doctrine\Tests\ORM\Mapping\User';
50
        return $this->createClassMetadata($entityClassName);
51
    }
52
53
    /**
54
     * @depends testLoadMapping
55
     * @param ClassMetadata $class
56
     */
57
    public function testEntityTableNameAndInheritance($class)
58
    {
59
        $this->assertEquals('cms_users', $class->getTableName());
60
        $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $class->inheritanceType);
61
62
        return $class;
63
    }
64
65
    /**
66
     * @depends testEntityTableNameAndInheritance
67
     * @param ClassMetadata $class
68
     */
69
    public function testEntityIndexes($class)
70
    {
71
        $this->assertArrayHasKey('indexes', $class->table, 'ClassMetadata should have indexes key in table property.');
72
        $this->assertEquals(array(
73
            'name_idx' => array('columns' => array('name')),
74
            0 => array('columns' => array('user_email'))
75
        ), $class->table['indexes']);
76
77
        return $class;
78
    }
79
80
    public function testEntityIndexFlagsAndPartialIndexes()
81
    {
82
        $class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\Comment');
83
84
        $this->assertEquals(array(
85
            0 => array(
86
                'columns' => array('content'),
87
                'flags' => array('fulltext'),
88
                'options' => array('where' => 'content IS NOT NULL'),
89
            )
90
        ), $class->table['indexes']);
91
    }
92
93
    /**
94
     * @depends testEntityTableNameAndInheritance
95
     * @param ClassMetadata $class
96
     */
97
    public function testEntityUniqueConstraints($class)
98
    {
99
        $this->assertArrayHasKey('uniqueConstraints', $class->table,
100
            'ClassMetadata should have uniqueConstraints key in table property when Unique Constraints are set.');
101
102
        $this->assertEquals(array(
103
            "search_idx" => array("columns" => array("name", "user_email"), 'options' => array('where' => 'name IS NOT NULL'))
104
        ), $class->table['uniqueConstraints']);
105
106
        return $class;
107
    }
108
109
    /**
110
     * @depends testEntityTableNameAndInheritance
111
     * @param ClassMetadata $class
112
     */
113
    public function testEntityOptions($class)
114
    {
115
        $this->assertArrayHasKey('options', $class->table, 'ClassMetadata should have options key in table property.');
116
117
        $this->assertEquals(array(
118
            'foo' => 'bar', 'baz' => array('key' => 'val')
119
        ), $class->table['options']);
120
121
        return $class;
122
    }
123
124
    /**
125
     * @depends testEntityOptions
126
     * @param ClassMetadata $class
127
     */
128
    public function testEntitySequence($class)
129
    {
130
        $this->assertInternalType('array', $class->sequenceGeneratorDefinition, 'No Sequence Definition set on this driver.');
131
        $this->assertEquals(
132
            array(
133
                'sequenceName' => 'tablename_seq',
134
                'allocationSize' => 100,
135
                'initialValue' => 1,
136
            ),
137
            $class->sequenceGeneratorDefinition
138
        );
139
    }
140
141
    public function testEntityCustomGenerator()
142
    {
143
        $class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\Animal');
144
145
        $this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM,
146
            $class->generatorType, "Generator Type");
147
        $this->assertEquals(
148
            array("class" => "stdClass"),
149
            $class->customGeneratorDefinition,
150
            "Custom Generator Definition");
151
    }
152
153
154
    /**
155
     * @depends testEntityTableNameAndInheritance
156
     * @param ClassMetadata $class
157
     */
158
    public function testFieldMappings($class)
159
    {
160
        $this->assertEquals(4, count($class->fieldMappings));
161
        $this->assertTrue(isset($class->fieldMappings['id']));
162
        $this->assertTrue(isset($class->fieldMappings['name']));
163
        $this->assertTrue(isset($class->fieldMappings['email']));
164
        $this->assertTrue(isset($class->fieldMappings['version']));
165
166
        return $class;
167
    }
168
169
    /**
170
     * @depends testFieldMappings
171
     * @param ClassMetadata $class
172
     */
173
    public function testVersionedField($class)
174
    {
175
        $this->assertTrue($class->isVersioned);
176
        $this->assertEquals("version", $class->versionField);
177
178
        $this->assertFalse(isset($class->fieldMappings['version']['version']));
179
    }
180
181
    /**
182
     * @depends testEntityTableNameAndInheritance
183
     * @param ClassMetadata $class
184
     */
185
    public function testFieldMappingsColumnNames($class)
186
    {
187
        $this->assertEquals("id", $class->fieldMappings['id']['columnName']);
188
        $this->assertEquals("name", $class->fieldMappings['name']['columnName']);
189
        $this->assertEquals("user_email", $class->fieldMappings['email']['columnName']);
190
191
        return $class;
192
    }
193
194
    /**
195
     * @depends testEntityTableNameAndInheritance
196
     * @param ClassMetadata $class
197
     */
198
    public function testStringFieldMappings($class)
199
    {
200
        $this->assertEquals('string', $class->fieldMappings['name']['type']);
201
        $this->assertEquals(50, $class->fieldMappings['name']['length']);
202
        $this->assertTrue($class->fieldMappings['name']['nullable']);
203
        $this->assertTrue($class->fieldMappings['name']['unique']);
204
205
        return $class;
206
    }
207
208
    /**
209
     * @depends testEntityTableNameAndInheritance
210
     * @param ClassMetadata $class
211
     */
212
    public function testFieldOptions($class)
213
    {
214
        $expected = array('foo' => 'bar', 'baz' => array('key' => 'val'));
215
        $this->assertEquals($expected, $class->fieldMappings['name']['options']);
216
217
        return $class;
218
    }
219
220
    /**
221
     * @depends testEntityTableNameAndInheritance
222
     * @param ClassMetadata $class
223
     */
224
    public function testIdFieldOptions($class)
225
    {
226
        $this->assertEquals(array('foo' => 'bar'), $class->fieldMappings['id']['options']);
227
228
        return $class;
229
    }
230
231
    /**
232
     * @depends testFieldMappings
233
     * @param ClassMetadata $class
234
     */
235
    public function testIdentifier($class)
236
    {
237
        $this->assertEquals(array('id'), $class->identifier);
238
        $this->assertEquals('integer', $class->fieldMappings['id']['type']);
239
        $this->assertEquals(ClassMetadata::GENERATOR_TYPE_AUTO, $class->generatorType, "ID-Generator is not ClassMetadata::GENERATOR_TYPE_AUTO");
240
241
        return $class;
242
    }
243
244
    /**
245
     * @depends testIdentifier
246
     * @param ClassMetadata $class
247
     */
248
    public function testAssociations($class)
249
    {
250
        $this->assertEquals(3, count($class->associationMappings));
251
252
        return $class;
253
    }
254
255
    /**
256
     * @depends testAssociations
257
     * @param ClassMetadata $class
258
     */
259
    public function testOwningOneToOneAssociation($class)
260
    {
261
        $this->assertTrue(isset($class->associationMappings['address']));
262
        $this->assertTrue($class->associationMappings['address']['isOwningSide']);
263
        $this->assertEquals('user', $class->associationMappings['address']['inversedBy']);
264
        // Check cascading
265
        $this->assertTrue($class->associationMappings['address']['isCascadeRemove']);
266
        $this->assertFalse($class->associationMappings['address']['isCascadePersist']);
267
        $this->assertFalse($class->associationMappings['address']['isCascadeRefresh']);
268
        $this->assertFalse($class->associationMappings['address']['isCascadeDetach']);
269
        $this->assertFalse($class->associationMappings['address']['isCascadeMerge']);
270
271
        return $class;
272
    }
273
274
    /**
275
     * @depends testOwningOneToOneAssociation
276
     * @param ClassMetadata $class
277
     */
278
    public function testInverseOneToManyAssociation($class)
279
    {
280
        $this->assertTrue(isset($class->associationMappings['phonenumbers']));
281
        $this->assertFalse($class->associationMappings['phonenumbers']['isOwningSide']);
282
        $this->assertTrue($class->associationMappings['phonenumbers']['isCascadePersist']);
283
        $this->assertTrue($class->associationMappings['phonenumbers']['isCascadeRemove']);
284
        $this->assertFalse($class->associationMappings['phonenumbers']['isCascadeRefresh']);
285
        $this->assertFalse($class->associationMappings['phonenumbers']['isCascadeDetach']);
286
        $this->assertFalse($class->associationMappings['phonenumbers']['isCascadeMerge']);
287
        $this->assertTrue($class->associationMappings['phonenumbers']['orphanRemoval']);
288
289
        // Test Order By
290
        $this->assertEquals(array('number' => 'ASC'), $class->associationMappings['phonenumbers']['orderBy']);
291
292
        return $class;
293
    }
294
295
    /**
296
     * @depends testInverseOneToManyAssociation
297
     * @param ClassMetadata $class
298
     */
299
    public function testManyToManyAssociationWithCascadeAll($class)
300
    {
301
        $this->assertTrue(isset($class->associationMappings['groups']));
302
        $this->assertTrue($class->associationMappings['groups']['isOwningSide']);
303
        // Make sure that cascade-all works as expected
304
        $this->assertTrue($class->associationMappings['groups']['isCascadeRemove']);
305
        $this->assertTrue($class->associationMappings['groups']['isCascadePersist']);
306
        $this->assertTrue($class->associationMappings['groups']['isCascadeRefresh']);
307
        $this->assertTrue($class->associationMappings['groups']['isCascadeDetach']);
308
        $this->assertTrue($class->associationMappings['groups']['isCascadeMerge']);
309
310
        $this->assertFalse(isset($class->associationMappings['groups']['orderBy']));
311
312
        return $class;
313
    }
314
315
    /**
316
     * @depends testManyToManyAssociationWithCascadeAll
317
     * @param ClassMetadata $class
318
     */
319
    public function testLifecycleCallbacks($class)
320
    {
321
        $this->assertEquals(count($class->lifecycleCallbacks), 2);
322
        $this->assertEquals($class->lifecycleCallbacks['prePersist'][0], 'doStuffOnPrePersist');
323
        $this->assertEquals($class->lifecycleCallbacks['postPersist'][0], 'doStuffOnPostPersist');
324
325
        return $class;
326
    }
327
328
    /**
329
     * @depends testManyToManyAssociationWithCascadeAll
330
     * @param ClassMetadata $class
331
     */
332
    public function testLifecycleCallbacksSupportMultipleMethodNames($class)
333
    {
334
        $this->assertEquals(count($class->lifecycleCallbacks['prePersist']), 2);
335
        $this->assertEquals($class->lifecycleCallbacks['prePersist'][1], 'doOtherStuffOnPrePersistToo');
336
337
        return $class;
338
    }
339
340
    /**
341
     * @depends testLifecycleCallbacksSupportMultipleMethodNames
342
     * @param ClassMetadata $class
343
     */
344
    public function testJoinColumnUniqueAndNullable($class)
345
    {
346
        // Non-Nullability of Join Column
347
        $this->assertFalse($class->associationMappings['groups']['joinTable']['joinColumns'][0]['nullable']);
348
        $this->assertFalse($class->associationMappings['groups']['joinTable']['joinColumns'][0]['unique']);
349
350
        return $class;
351
    }
352
353
    /**
354
     * @depends testJoinColumnUniqueAndNullable
355
     * @param ClassMetadata $class
356
     */
357
    public function testColumnDefinition($class)
358
    {
359
        $this->assertEquals("CHAR(32) NOT NULL", $class->fieldMappings['email']['columnDefinition']);
360
        $this->assertEquals("INT NULL", $class->associationMappings['groups']['joinTable']['inverseJoinColumns'][0]['columnDefinition']);
361
362
        return $class;
363
    }
364
365
    /**
366
     * @depends testColumnDefinition
367
     * @param ClassMetadata $class
368
     */
369
    public function testJoinColumnOnDelete($class)
370
    {
371
        $this->assertEquals('CASCADE', $class->associationMappings['address']['joinColumns'][0]['onDelete']);
372
373
        return $class;
374
    }
375
376
    /**
377
     * @group DDC-514
378
     */
379
    public function testDiscriminatorColumnDefaults()
380
    {
381
        if (strpos(get_class($this), 'PHPMappingDriver') !== false) {
382
            $this->markTestSkipped('PHP Mapping Drivers have no defaults.');
383
        }
384
385
        $class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\Animal');
386
387
        $this->assertEquals(
388
            array('name' => 'discr', 'type' => 'string', 'length' => '32', 'fieldName' => 'discr', 'columnDefinition' => null),
389
            $class->discriminatorColumn
390
        );
391
    }
392
393
    /**
394
     * @group DDC-869
395
     */
396
    public function testMappedSuperclassWithRepository()
397
    {
398
        $em         = $this->_getTestEntityManager();
399
        $factory    = $this->createClassMetadataFactory($em);
400
401
402
        $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment');
403
404
        $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...
405
        $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...
406
        $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...
407
        $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...
408
        $this->assertInstanceOf("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository",
409
             $em->getRepository("Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment"));
410
        $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...
411
412
413
414
        $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869ChequePayment');
415
416
        $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...
417
        $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...
418
        $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...
419
        $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...
420
        $this->assertInstanceOf("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository",
421
             $em->getRepository("Doctrine\Tests\Models\DDC869\DDC869ChequePayment"));
422
        $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...
423
    }
424
425
    /**
426
     * @group DDC-1476
427
     */
428
    public function testDefaultFieldType()
429
    {
430
        $factory    = $this->createClassMetadataFactory();
431
        $class      = $factory->getMetadataFor('Doctrine\Tests\Models\DDC1476\DDC1476EntityWithDefaultFieldType');
432
433
434
        $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...
435
        $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...
436
437
438
        $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...
439
        $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...
440
441
        $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...
442
        $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...
443
444
445
446
        $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...
447
        $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...
448
449
        $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...
450
        $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...
451
452
453
454
        $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...
455
        $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...
456
457
        $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...
458
        $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...
459
460
        $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...
461
    }
462
463
    /**
464
     * @group DDC-1170
465
     */
466
    public function testIdentifierColumnDefinition()
467
    {
468
        $class = $this->createClassMetadata(__NAMESPACE__ . '\DDC1170Entity');
469
470
471
        $this->assertArrayHasKey('id', $class->fieldMappings);
472
        $this->assertArrayHasKey('value', $class->fieldMappings);
473
474
        $this->assertArrayHasKey('columnDefinition', $class->fieldMappings['id']);
475
        $this->assertArrayHasKey('columnDefinition', $class->fieldMappings['value']);
476
477
        $this->assertEquals("INT unsigned NOT NULL", $class->fieldMappings['id']['columnDefinition']);
478
        $this->assertEquals("VARCHAR(255) NOT NULL", $class->fieldMappings['value']['columnDefinition']);
479
    }
480
481
    /**
482
     * @group DDC-559
483
     */
484
    public function testNamingStrategy()
485
    {
486
        $em         = $this->_getTestEntityManager();
487
        $factory    = $this->createClassMetadataFactory($em);
488
489
490
        $this->assertInstanceOf('Doctrine\ORM\Mapping\DefaultNamingStrategy', $em->getConfiguration()->getNamingStrategy());
491
        $em->getConfiguration()->setNamingStrategy(new \Doctrine\ORM\Mapping\UnderscoreNamingStrategy(CASE_UPPER));
492
        $this->assertInstanceOf('Doctrine\ORM\Mapping\UnderscoreNamingStrategy', $em->getConfiguration()->getNamingStrategy());
493
494
        $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC1476\DDC1476EntityWithDefaultFieldType');
495
496
        $this->assertEquals('ID', $class->getColumnName('id'));
497
        $this->assertEquals('NAME', $class->getColumnName('name'));
498
        $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...
499
    }
500
501
    /**
502
     * @group DDC-807
503
     * @group DDC-553
504
     */
505
    public function testDiscriminatorColumnDefinition()
506
    {
507
        $class = $this->createClassMetadata(__NAMESPACE__ . '\DDC807Entity');
508
509
        $this->assertArrayHasKey('columnDefinition', $class->discriminatorColumn);
510
        $this->assertArrayHasKey('name', $class->discriminatorColumn);
511
512
        $this->assertEquals("ENUM('ONE','TWO')", $class->discriminatorColumn['columnDefinition']);
513
        $this->assertEquals("dtype", $class->discriminatorColumn['name']);
514
    }
515
516
    /**
517
     * @group DDC-889
518
     */
519
    public function testInvalidEntityOrMappedSuperClassShouldMentionParentClasses()
520
    {
521
        $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', 'Class "Doctrine\Tests\Models\DDC889\DDC889Class" sub class of "Doctrine\Tests\Models\DDC889\DDC889SuperClass" is not a valid entity or mapped super class.');
522
523
        $this->createClassMetadata('Doctrine\Tests\Models\DDC889\DDC889Class');
524
    }
525
526
    /**
527
     * @group DDC-889
528
     */
529
    public function testIdentifierRequiredShouldMentionParentClasses()
530
    {
531
        $factory = $this->createClassMetadataFactory();
532
533
        $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', '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.');
534
        $factory->getMetadataFor('Doctrine\Tests\Models\DDC889\DDC889Entity');
535
    }
536
537
    public function testNamedQuery()
538
    {
539
        $driver = $this->_loadDriver();
540
        $class = $this->createClassMetadata(__NAMESPACE__.'\User');
541
542
        $this->assertCount(1, $class->getNamedQueries(), sprintf("Named queries not processed correctly by driver %s", get_class($driver)));
543
    }
544
545
    /**
546
     * @group DDC-1663
547
     */
548
    public function testNamedNativeQuery()
549
    {
550
551
        $class = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress');
552
553
        //named native query
554
        $this->assertCount(3, $class->namedNativeQueries);
555
        $this->assertArrayHasKey('find-all', $class->namedNativeQueries);
556
        $this->assertArrayHasKey('find-by-id', $class->namedNativeQueries);
557
558
559
        $findAllQuery = $class->getNamedNativeQuery('find-all');
560
        $this->assertEquals('find-all', $findAllQuery['name']);
561
        $this->assertEquals('mapping-find-all', $findAllQuery['resultSetMapping']);
562
        $this->assertEquals('SELECT id, country, city FROM cms_addresses', $findAllQuery['query']);
563
564
        $findByIdQuery = $class->getNamedNativeQuery('find-by-id');
565
        $this->assertEquals('find-by-id', $findByIdQuery['name']);
566
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress',$findByIdQuery['resultClass']);
567
        $this->assertEquals('SELECT * FROM cms_addresses WHERE id = ?',  $findByIdQuery['query']);
568
569
        $countQuery = $class->getNamedNativeQuery('count');
570
        $this->assertEquals('count', $countQuery['name']);
571
        $this->assertEquals('mapping-count', $countQuery['resultSetMapping']);
572
        $this->assertEquals('SELECT COUNT(*) AS count FROM cms_addresses',  $countQuery['query']);
573
574
        // result set mapping
575
        $this->assertCount(3, $class->sqlResultSetMappings);
576
        $this->assertArrayHasKey('mapping-count', $class->sqlResultSetMappings);
577
        $this->assertArrayHasKey('mapping-find-all', $class->sqlResultSetMappings);
578
        $this->assertArrayHasKey('mapping-without-fields', $class->sqlResultSetMappings);
579
580
        $findAllMapping = $class->getSqlResultSetMapping('mapping-find-all');
581
        $this->assertEquals('mapping-find-all', $findAllMapping['name']);
582
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress', $findAllMapping['entities'][0]['entityClass']);
583
        $this->assertEquals(array('name'=>'id','column'=>'id'), $findAllMapping['entities'][0]['fields'][0]);
584
        $this->assertEquals(array('name'=>'city','column'=>'city'), $findAllMapping['entities'][0]['fields'][1]);
585
        $this->assertEquals(array('name'=>'country','column'=>'country'), $findAllMapping['entities'][0]['fields'][2]);
586
587
        $withoutFieldsMapping = $class->getSqlResultSetMapping('mapping-without-fields');
588
        $this->assertEquals('mapping-without-fields', $withoutFieldsMapping['name']);
589
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress', $withoutFieldsMapping['entities'][0]['entityClass']);
590
        $this->assertEquals(array(), $withoutFieldsMapping['entities'][0]['fields']);
591
592
        $countMapping = $class->getSqlResultSetMapping('mapping-count');
593
        $this->assertEquals('mapping-count', $countMapping['name']);
594
        $this->assertEquals(array('name'=>'count'), $countMapping['columns'][0]);
595
596
    }
597
598
    /**
599
     * @group DDC-1663
600
     */
601
    public function testSqlResultSetMapping()
602
    {
603
604
        $userMetadata   = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
605
        $personMetadata = $this->createClassMetadata('Doctrine\Tests\Models\Company\CompanyPerson');
606
607
        // user asserts
608
        $this->assertCount(4, $userMetadata->getSqlResultSetMappings());
609
610
        $mapping = $userMetadata->getSqlResultSetMapping('mappingJoinedAddress');
611
        $this->assertEquals(array(),$mapping['columns']);
612
        $this->assertEquals('mappingJoinedAddress', $mapping['name']);
613
        $this->assertNull($mapping['entities'][0]['discriminatorColumn']);
614
        $this->assertEquals(array('name'=>'id','column'=>'id'),                     $mapping['entities'][0]['fields'][0]);
615
        $this->assertEquals(array('name'=>'name','column'=>'name'),                 $mapping['entities'][0]['fields'][1]);
616
        $this->assertEquals(array('name'=>'status','column'=>'status'),             $mapping['entities'][0]['fields'][2]);
617
        $this->assertEquals(array('name'=>'address.zip','column'=>'zip'),           $mapping['entities'][0]['fields'][3]);
618
        $this->assertEquals(array('name'=>'address.city','column'=>'city'),         $mapping['entities'][0]['fields'][4]);
619
        $this->assertEquals(array('name'=>'address.country','column'=>'country'),   $mapping['entities'][0]['fields'][5]);
620
        $this->assertEquals(array('name'=>'address.id','column'=>'a_id'),           $mapping['entities'][0]['fields'][6]);
621
        $this->assertEquals($userMetadata->name,                                    $mapping['entities'][0]['entityClass']);
622
623
624
        $mapping = $userMetadata->getSqlResultSetMapping('mappingJoinedPhonenumber');
625
        $this->assertEquals(array(),$mapping['columns']);
626
        $this->assertEquals('mappingJoinedPhonenumber', $mapping['name']);
627
        $this->assertNull($mapping['entities'][0]['discriminatorColumn']);
628
        $this->assertEquals(array('name'=>'id','column'=>'id'),                             $mapping['entities'][0]['fields'][0]);
629
        $this->assertEquals(array('name'=>'name','column'=>'name'),                         $mapping['entities'][0]['fields'][1]);
630
        $this->assertEquals(array('name'=>'status','column'=>'status'),                     $mapping['entities'][0]['fields'][2]);
631
        $this->assertEquals(array('name'=>'phonenumbers.phonenumber','column'=>'number'),   $mapping['entities'][0]['fields'][3]);
632
        $this->assertEquals($userMetadata->name,                                            $mapping['entities'][0]['entityClass']);
633
634
        $mapping = $userMetadata->getSqlResultSetMapping('mappingUserPhonenumberCount');
635
        $this->assertEquals(array('name'=>'numphones'),$mapping['columns'][0]);
636
        $this->assertEquals('mappingUserPhonenumberCount', $mapping['name']);
637
        $this->assertNull($mapping['entities'][0]['discriminatorColumn']);
638
        $this->assertEquals(array('name'=>'id','column'=>'id'),         $mapping['entities'][0]['fields'][0]);
639
        $this->assertEquals(array('name'=>'name','column'=>'name'),     $mapping['entities'][0]['fields'][1]);
640
        $this->assertEquals(array('name'=>'status','column'=>'status'), $mapping['entities'][0]['fields'][2]);
641
        $this->assertEquals($userMetadata->name,                        $mapping['entities'][0]['entityClass']);
642
643
        $mapping = $userMetadata->getSqlResultSetMapping('mappingMultipleJoinsEntityResults');
644
        $this->assertEquals(array('name'=>'numphones'),$mapping['columns'][0]);
645
        $this->assertEquals('mappingMultipleJoinsEntityResults', $mapping['name']);
646
        $this->assertNull($mapping['entities'][0]['discriminatorColumn']);
647
        $this->assertEquals(array('name'=>'id','column'=>'u_id'),           $mapping['entities'][0]['fields'][0]);
648
        $this->assertEquals(array('name'=>'name','column'=>'u_name'),       $mapping['entities'][0]['fields'][1]);
649
        $this->assertEquals(array('name'=>'status','column'=>'u_status'),   $mapping['entities'][0]['fields'][2]);
650
        $this->assertEquals($userMetadata->name,                            $mapping['entities'][0]['entityClass']);
651
        $this->assertNull($mapping['entities'][1]['discriminatorColumn']);
652
        $this->assertEquals(array('name'=>'id','column'=>'a_id'),           $mapping['entities'][1]['fields'][0]);
653
        $this->assertEquals(array('name'=>'zip','column'=>'a_zip'),         $mapping['entities'][1]['fields'][1]);
654
        $this->assertEquals(array('name'=>'country','column'=>'a_country'), $mapping['entities'][1]['fields'][2]);
655
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress',         $mapping['entities'][1]['entityClass']);
656
657
        //person asserts
658
        $this->assertCount(1, $personMetadata->getSqlResultSetMappings());
659
660
        $mapping = $personMetadata->getSqlResultSetMapping('mappingFetchAll');
661
        $this->assertEquals(array(),$mapping['columns']);
662
        $this->assertEquals('mappingFetchAll', $mapping['name']);
663
        $this->assertEquals('discriminator',                            $mapping['entities'][0]['discriminatorColumn']);
664
        $this->assertEquals(array('name'=>'id','column'=>'id'),         $mapping['entities'][0]['fields'][0]);
665
        $this->assertEquals(array('name'=>'name','column'=>'name'),     $mapping['entities'][0]['fields'][1]);
666
        $this->assertEquals($personMetadata->name,                      $mapping['entities'][0]['entityClass']);
667
    }
668
669
    /*
670
     * @group DDC-964
671
     */
672
    public function testAssociationOverridesMapping()
673
    {
674
675
        $factory        = $this->createClassMetadataFactory();
676
        $adminMetadata  = $factory->getMetadataFor('Doctrine\Tests\Models\DDC964\DDC964Admin');
677
        $guestMetadata  = $factory->getMetadataFor('Doctrine\Tests\Models\DDC964\DDC964Guest');
678
679
680
        // assert groups association mappings
681
        $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...
682
        $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...
683
684
        $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...
685
        $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...
686
687
        // assert not override attributes
688
        $this->assertEquals($guestGroups['fieldName'], $adminGroups['fieldName']);
689
        $this->assertEquals($guestGroups['type'], $adminGroups['type']);
690
        $this->assertEquals($guestGroups['mappedBy'], $adminGroups['mappedBy']);
691
        $this->assertEquals($guestGroups['inversedBy'], $adminGroups['inversedBy']);
692
        $this->assertEquals($guestGroups['isOwningSide'], $adminGroups['isOwningSide']);
693
        $this->assertEquals($guestGroups['fetch'], $adminGroups['fetch']);
694
        $this->assertEquals($guestGroups['isCascadeRemove'], $adminGroups['isCascadeRemove']);
695
        $this->assertEquals($guestGroups['isCascadePersist'], $adminGroups['isCascadePersist']);
696
        $this->assertEquals($guestGroups['isCascadeRefresh'], $adminGroups['isCascadeRefresh']);
697
        $this->assertEquals($guestGroups['isCascadeMerge'], $adminGroups['isCascadeMerge']);
698
        $this->assertEquals($guestGroups['isCascadeDetach'], $adminGroups['isCascadeDetach']);
699
700
         // assert not override attributes
701
        $this->assertEquals('ddc964_users_groups', $guestGroups['joinTable']['name']);
702
        $this->assertEquals('user_id', $guestGroups['joinTable']['joinColumns'][0]['name']);
703
        $this->assertEquals('group_id', $guestGroups['joinTable']['inverseJoinColumns'][0]['name']);
704
705
        $this->assertEquals(array('user_id'=>'id'), $guestGroups['relationToSourceKeyColumns']);
706
        $this->assertEquals(array('group_id'=>'id'), $guestGroups['relationToTargetKeyColumns']);
707
        $this->assertEquals(array('user_id','group_id'), $guestGroups['joinTableColumns']);
708
709
710
        $this->assertEquals('ddc964_users_admingroups', $adminGroups['joinTable']['name']);
711
        $this->assertEquals('adminuser_id', $adminGroups['joinTable']['joinColumns'][0]['name']);
712
        $this->assertEquals('admingroup_id', $adminGroups['joinTable']['inverseJoinColumns'][0]['name']);
713
714
        $this->assertEquals(array('adminuser_id'=>'id'), $adminGroups['relationToSourceKeyColumns']);
715
        $this->assertEquals(array('admingroup_id'=>'id'), $adminGroups['relationToTargetKeyColumns']);
716
        $this->assertEquals(array('adminuser_id','admingroup_id'), $adminGroups['joinTableColumns']);
717
718
719
        // assert address association mappings
720
        $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...
721
        $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...
722
723
        $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...
724
        $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...
725
726
        // assert not override attributes
727
        $this->assertEquals($guestAddress['fieldName'], $adminAddress['fieldName']);
728
        $this->assertEquals($guestAddress['type'], $adminAddress['type']);
729
        $this->assertEquals($guestAddress['mappedBy'], $adminAddress['mappedBy']);
730
        $this->assertEquals($guestAddress['inversedBy'], $adminAddress['inversedBy']);
731
        $this->assertEquals($guestAddress['isOwningSide'], $adminAddress['isOwningSide']);
732
        $this->assertEquals($guestAddress['fetch'], $adminAddress['fetch']);
733
        $this->assertEquals($guestAddress['isCascadeRemove'], $adminAddress['isCascadeRemove']);
734
        $this->assertEquals($guestAddress['isCascadePersist'], $adminAddress['isCascadePersist']);
735
        $this->assertEquals($guestAddress['isCascadeRefresh'], $adminAddress['isCascadeRefresh']);
736
        $this->assertEquals($guestAddress['isCascadeMerge'], $adminAddress['isCascadeMerge']);
737
        $this->assertEquals($guestAddress['isCascadeDetach'], $adminAddress['isCascadeDetach']);
738
739
        // assert override
740
        $this->assertEquals('address_id', $guestAddress['joinColumns'][0]['name']);
741
        $this->assertEquals(array('address_id'=>'id'), $guestAddress['sourceToTargetKeyColumns']);
742
        $this->assertEquals(array('address_id'=>'address_id'), $guestAddress['joinColumnFieldNames']);
743
        $this->assertEquals(array('id'=>'address_id'), $guestAddress['targetToSourceKeyColumns']);
744
745
746
        $this->assertEquals('adminaddress_id', $adminAddress['joinColumns'][0]['name']);
747
        $this->assertEquals(array('adminaddress_id'=>'id'), $adminAddress['sourceToTargetKeyColumns']);
748
        $this->assertEquals(array('adminaddress_id'=>'adminaddress_id'), $adminAddress['joinColumnFieldNames']);
749
        $this->assertEquals(array('id'=>'adminaddress_id'), $adminAddress['targetToSourceKeyColumns']);
750
    }
751
752
    /*
753
     * @group DDC-3579
754
     */
755
    public function testInversedByOverrideMapping()
756
    {
757
758
        $factory        = $this->createClassMetadataFactory();
759
        $adminMetadata  = $factory->getMetadataFor('Doctrine\Tests\Models\DDC3579\DDC3579Admin');
760
761
        // assert groups association mappings
762
        $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...
763
        $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...
764
765
        // assert override
766
        $this->assertEquals('admins', $adminGroups['inversedBy']);
767
    }
768
769
    /**
770
     * @group DDC-964
771
     */
772
    public function testAttributeOverridesMapping()
773
    {
774
775
        $factory       = $this->createClassMetadataFactory();
776
        $guestMetadata = $factory->getMetadataFor('Doctrine\Tests\Models\DDC964\DDC964Guest');
777
        $adminMetadata = $factory->getMetadataFor('Doctrine\Tests\Models\DDC964\DDC964Admin');
778
779
        $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...
780
        $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...
781
        $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...
782
        $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...
783
        $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...
784
        $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...
785
786
787
        $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...
788
        $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...
789
        $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...
790
        $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...
791
        $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...
792
793
794
        $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...
795
        $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...
796
        $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...
797
        $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...
798
        $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...
799
        $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...
800
801
        $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...
802
        $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...
803
        $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...
804
        $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...
805
        $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...
806
    }
807
808
    /**
809
     * @group DDC-1955
810
     */
811
    public function testEntityListeners()
812
    {
813
        $em         = $this->_getTestEntityManager();
814
        $factory    = $this->createClassMetadataFactory($em);
815
        $superClass = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyContract');
816
        $flexClass  = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyFixContract');
817
        $fixClass   = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyFlexContract');
818
        $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...
819
820
        $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...
821
        $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...
822
823
        $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...
824
        $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...
825
826
        $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...
827
        $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...
828
829
        $this->assertEquals('Doctrine\Tests\Models\Company\CompanyContractListener', $postPersist['class']);
830
        $this->assertEquals('Doctrine\Tests\Models\Company\CompanyContractListener', $prePersist['class']);
831
        $this->assertEquals('postPersistHandler', $postPersist['method']);
832
        $this->assertEquals('prePersistHandler', $prePersist['method']);
833
834
        //Inherited listeners
835
        $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...
836
        $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...
837
    }
838
839
    /**
840
     * @group DDC-1955
841
     */
842
    public function testEntityListenersOverride()
843
    {
844
        $em         = $this->_getTestEntityManager();
845
        $factory    = $this->createClassMetadataFactory($em);
846
        $ultraClass = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyFlexUltraContract');
847
848
        //overridden listeners
849
        $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...
850
        $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...
851
852
        $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...
853
        $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...
854
855
        $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...
856
        $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...
857
858
        $this->assertEquals('Doctrine\Tests\Models\Company\CompanyContractListener', $postPersist['class']);
859
        $this->assertEquals('Doctrine\Tests\Models\Company\CompanyContractListener', $prePersist['class']);
860
        $this->assertEquals('postPersistHandler', $postPersist['method']);
861
        $this->assertEquals('prePersistHandler', $prePersist['method']);
862
863
        $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...
864
        $this->assertEquals('Doctrine\Tests\Models\Company\CompanyFlexUltraContractListener', $prePersist['class']);
865
        $this->assertEquals('prePersistHandler1', $prePersist['method']);
866
867
        $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...
868
        $this->assertEquals('Doctrine\Tests\Models\Company\CompanyFlexUltraContractListener', $prePersist['class']);
869
        $this->assertEquals('prePersistHandler2', $prePersist['method']);
870
    }
871
872
873
    /**
874
     * @group DDC-1955
875
     */
876
    public function testEntityListenersNamingConvention()
877
    {
878
        $em         = $this->_getTestEntityManager();
879
        $factory    = $this->createClassMetadataFactory($em);
880
        $metadata   = $factory->getMetadataFor('Doctrine\Tests\Models\CMS\CmsAddress');
881
882
        $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...
883
        $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...
884
        $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...
885
        $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...
886
        $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...
887
        $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...
888
        $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...
889
        $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...
890
891
        $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...
892
        $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...
893
        $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...
894
        $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...
895
        $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...
896
        $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...
897
        $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...
898
        $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...
899
900
        $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...
901
        $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...
902
        $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...
903
        $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...
904
        $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...
905
        $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...
906
        $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...
907
        $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...
908
909
910
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $postPersist['class']);
911
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $prePersist['class']);
912
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $postUpdate['class']);
913
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $preUpdate['class']);
914
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $postRemove['class']);
915
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $preRemove['class']);
916
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $postLoad['class']);
917
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $preFlush['class']);
918
919
        $this->assertEquals(Events::postPersist, $postPersist['method']);
920
        $this->assertEquals(Events::prePersist, $prePersist['method']);
921
        $this->assertEquals(Events::postUpdate, $postUpdate['method']);
922
        $this->assertEquals(Events::preUpdate, $preUpdate['method']);
923
        $this->assertEquals(Events::postRemove, $postRemove['method']);
924
        $this->assertEquals(Events::preRemove, $preRemove['method']);
925
        $this->assertEquals(Events::postLoad, $postLoad['method']);
926
        $this->assertEquals(Events::preFlush, $preFlush['method']);
927
    }
928
929
    /**
930
     * @group DDC-2183
931
     */
932
    public function testSecondLevelCacheMapping()
933
    {
934
        $em      = $this->_getTestEntityManager();
935
        $factory = $this->createClassMetadataFactory($em);
936
        $class   = $factory->getMetadataFor(City::CLASSNAME);
937
        $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...
938
        $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...
939
        $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...
940
        $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...
941
942
        $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...
943
        $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...
944
        $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...
945
        $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...
946
        $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...
947
        $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...
948
949
        $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...
950
        $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...
951
        $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...
952
        $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...
953
        $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...
954
        $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...
955
    }
956
957
    /**
958
     * @group DDC-2825
959
     * @group 881
960
     */
961
    public function testSchemaDefinitionViaExplicitTableSchemaAnnotationProperty()
962
    {
963
        /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */
964
        $metadata = $this->createClassMetadataFactory()->getMetadataFor(ExplicitSchemaAndTable::CLASSNAME);
965
966
        $this->assertSame('explicit_schema', $metadata->getSchemaName());
967
        $this->assertSame('explicit_table', $metadata->getTableName());
968
    }
969
970
    /**
971
     * @group DDC-2825
972
     * @group 881
973
     */
974
    public function testSchemaDefinitionViaSchemaDefinedInTableNameInTableAnnotationProperty()
975
    {
976
        /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */
977
        $metadata = $this->createClassMetadataFactory()->getMetadataFor(SchemaAndTableInTableName::CLASSNAME);
978
979
        $this->assertSame('implicit_schema', $metadata->getSchemaName());
980
        $this->assertSame('implicit_table', $metadata->getTableName());
981
    }
982
983
    /**
984
     * @group DDC-514
985
     * @group DDC-1015
986
     */
987
    public function testDiscriminatorColumnDefaultLength()
988
    {
989
        if (strpos(get_class($this), 'PHPMappingDriver') !== false) {
990
            $this->markTestSkipped('PHP Mapping Drivers have no defaults.');
991
        }
992
        $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityNoDiscriminatorColumnMapping');
993
        $this->assertEquals(255, $class->discriminatorColumn['length']);
994
        $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityIncompleteDiscriminatorColumnMapping');
995
        $this->assertEquals(255, $class->discriminatorColumn['length']);
996
    }
997
998
    /**
999
     * @group DDC-514
1000
     * @group DDC-1015
1001
     */
1002
    public function testDiscriminatorColumnDefaultType()
1003
    {
1004
        if (strpos(get_class($this), 'PHPMappingDriver') !== false) {
1005
            $this->markTestSkipped('PHP Mapping Drivers have no defaults.');
1006
        }
1007
        $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityNoDiscriminatorColumnMapping');
1008
        $this->assertEquals('string', $class->discriminatorColumn['type']);
1009
        $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityIncompleteDiscriminatorColumnMapping');
1010
        $this->assertEquals('string', $class->discriminatorColumn['type']);
1011
    }
1012
1013
    /**
1014
     * @group DDC-514
1015
     * @group DDC-1015
1016
     */
1017
    public function testDiscriminatorColumnDefaultName()
1018
    {
1019
        if (strpos(get_class($this), 'PHPMappingDriver') !== false) {
1020
            $this->markTestSkipped('PHP Mapping Drivers have no defaults.');
1021
        }
1022
        $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityNoDiscriminatorColumnMapping');
1023
        $this->assertEquals('dtype', $class->discriminatorColumn['name']);
1024
        $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityIncompleteDiscriminatorColumnMapping');
1025
        $this->assertEquals('dtype', $class->discriminatorColumn['name']);
1026
    }
1027
1028
}
1029
1030
/**
1031
 * @Entity
1032
 * @HasLifecycleCallbacks
1033
 * @Table(
1034
 *  name="cms_users",
1035
 *  uniqueConstraints={@UniqueConstraint(name="search_idx", columns={"name", "user_email"}, options={"where": "name IS NOT NULL"})},
1036
 *  indexes={@Index(name="name_idx", columns={"name"}), @Index(name="0", columns={"user_email"})},
1037
 *  options={"foo": "bar", "baz": {"key": "val"}}
1038
 * )
1039
 * @NamedQueries({@NamedQuery(name="all", query="SELECT u FROM __CLASS__ u")})
1040
 */
1041
class User
1042
{
1043
    /**
1044
     * @Id
1045
     * @Column(type="integer", options={"foo": "bar"})
1046
     * @generatedValue(strategy="AUTO")
1047
     * @SequenceGenerator(sequenceName="tablename_seq", initialValue=1, allocationSize=100)
1048
     **/
1049
    public $id;
1050
1051
    /**
1052
     * @Column(length=50, nullable=true, unique=true, options={"foo": "bar", "baz": {"key": "val"}})
1053
     */
1054
    public $name;
1055
1056
    /**
1057
     * @Column(name="user_email", columnDefinition="CHAR(32) NOT NULL")
1058
     */
1059
    public $email;
1060
1061
    /**
1062
     * @OneToOne(targetEntity="Address", cascade={"remove"}, inversedBy="user")
1063
     * @JoinColumn(onDelete="CASCADE")
1064
     */
1065
    public $address;
1066
1067
    /**
1068
     * @OneToMany(targetEntity="Phonenumber", mappedBy="user", cascade={"persist"}, orphanRemoval=true)
1069
     * @OrderBy({"number"="ASC"})
1070
     */
1071
    public $phonenumbers;
1072
1073
    /**
1074
     * @ManyToMany(targetEntity="Group", cascade={"all"})
1075
     * @JoinTable(name="cms_user_groups",
1076
     *    joinColumns={@JoinColumn(name="user_id", referencedColumnName="id", nullable=false, unique=false)},
1077
     *    inverseJoinColumns={@JoinColumn(name="group_id", referencedColumnName="id", columnDefinition="INT NULL")}
1078
     * )
1079
     */
1080
    public $groups;
1081
1082
    /**
1083
     * @Column(type="integer")
1084
     * @Version
1085
     */
1086
    public $version;
1087
1088
1089
    /**
1090
     * @PrePersist
1091
     */
1092
    public function doStuffOnPrePersist()
1093
    {
1094
    }
1095
1096
    /**
1097
     * @PrePersist
1098
     */
1099
    public function doOtherStuffOnPrePersistToo() {
1100
    }
1101
1102
    /**
1103
     * @PostPersist
1104
     */
1105
    public function doStuffOnPostPersist()
1106
    {
1107
1108
    }
1109
1110
    public static function loadMetadata(ClassMetadataInfo $metadata)
1111
    {
1112
        $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
1113
        $metadata->setPrimaryTable(array(
1114
           'name' => 'cms_users',
1115
           'options' => array('foo' => 'bar', 'baz' => array('key' => 'val')),
1116
          ));
1117
        $metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT);
1118
        $metadata->addLifecycleCallback('doStuffOnPrePersist', 'prePersist');
1119
        $metadata->addLifecycleCallback('doOtherStuffOnPrePersistToo', 'prePersist');
1120
        $metadata->addLifecycleCallback('doStuffOnPostPersist', 'postPersist');
1121
        $metadata->mapField(array(
1122
           'id' => true,
1123
           'fieldName' => 'id',
1124
           'type' => 'integer',
1125
           'columnName' => 'id',
1126
           'options' => array('foo' => 'bar'),
1127
          ));
1128
        $metadata->mapField(array(
1129
           'fieldName' => 'name',
1130
           'type' => 'string',
1131
           'length' => 50,
1132
           'unique' => true,
1133
           'nullable' => true,
1134
           'columnName' => 'name',
1135
           'options' => array('foo' => 'bar', 'baz' => array('key' => 'val')),
1136
          ));
1137
        $metadata->mapField(array(
1138
           'fieldName' => 'email',
1139
           'type' => 'string',
1140
           'columnName' => 'user_email',
1141
           'columnDefinition' => 'CHAR(32) NOT NULL',
1142
          ));
1143
        $mapping = array('fieldName' => 'version', 'type' => 'integer');
1144
        $metadata->setVersionMapping($mapping);
1145
        $metadata->mapField($mapping);
1146
        $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
1147
        $metadata->mapOneToOne(array(
1148
           'fieldName' => 'address',
1149
           'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Address',
1150
           'cascade' =>
1151
           array(
1152
           0 => 'remove',
1153
           ),
1154
           'mappedBy' => NULL,
1155
           'inversedBy' => 'user',
1156
           'joinColumns' =>
1157
           array(
1158
           0 =>
1159
           array(
1160
            'name' => 'address_id',
1161
            'referencedColumnName' => 'id',
1162
            'onDelete' => 'CASCADE',
1163
           ),
1164
           ),
1165
           'orphanRemoval' => false,
1166
          ));
1167
        $metadata->mapOneToMany(array(
1168
           'fieldName' => 'phonenumbers',
1169
           'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Phonenumber',
1170
           'cascade' =>
1171
           array(
1172
           1 => 'persist',
1173
           ),
1174
           'mappedBy' => 'user',
1175
           'orphanRemoval' => true,
1176
           'orderBy' =>
1177
           array(
1178
           'number' => 'ASC',
1179
           ),
1180
          ));
1181
        $metadata->mapManyToMany(array(
1182
           'fieldName' => 'groups',
1183
           'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Group',
1184
           'cascade' =>
1185
           array(
1186
           0 => 'remove',
1187
           1 => 'persist',
1188
           2 => 'refresh',
1189
           3 => 'merge',
1190
           4 => 'detach',
1191
           ),
1192
           'mappedBy' => NULL,
1193
           'joinTable' =>
1194
           array(
1195
           'name' => 'cms_users_groups',
1196
           'joinColumns' =>
1197
           array(
1198
            0 =>
1199
            array(
1200
            'name' => 'user_id',
1201
            'referencedColumnName' => 'id',
1202
            'unique' => false,
1203
            'nullable' => false,
1204
            ),
1205
           ),
1206
           'inverseJoinColumns' =>
1207
           array(
1208
            0 =>
1209
            array(
1210
            'name' => 'group_id',
1211
            'referencedColumnName' => 'id',
1212
            'columnDefinition' => 'INT NULL',
1213
            ),
1214
           ),
1215
           ),
1216
           'orderBy' => NULL,
1217
          ));
1218
        $metadata->table['uniqueConstraints'] = array(
1219
            'search_idx' => array('columns' => array('name', 'user_email'), 'options'=> array('where' => 'name IS NOT NULL')),
1220
        );
1221
        $metadata->table['indexes'] = array(
1222
            'name_idx' => array('columns' => array('name')), 0 => array('columns' => array('user_email'))
1223
        );
1224
        $metadata->setSequenceGeneratorDefinition(array(
1225
                'sequenceName' => 'tablename_seq',
1226
                'allocationSize' => 100,
1227
                'initialValue' => 1,
1228
            ));
1229
        $metadata->addNamedQuery(array(
1230
                'name' => 'all',
1231
                'query' => 'SELECT u FROM __CLASS__ u'
1232
            ));
1233
    }
1234
}
1235
1236
/**
1237
 * @Entity
1238
 * @InheritanceType("SINGLE_TABLE")
1239
 * @DiscriminatorMap({"cat" = "Cat", "dog" = "Dog"})
1240
 * @DiscriminatorColumn(name="discr", length=32, type="string")
1241
 */
1242
abstract class Animal
1243
{
1244
    /**
1245
     * @Id @Column(type="string") @GeneratedValue(strategy="CUSTOM")
1246
     * @CustomIdGenerator(class="stdClass")
1247
     */
1248
    public $id;
1249
1250
    public static function loadMetadata(ClassMetadataInfo $metadata)
1251
    {
1252
        $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_CUSTOM);
1253
        $metadata->setCustomGeneratorDefinition(array("class" => "stdClass"));
1254
    }
1255
}
1256
1257
/** @Entity */
1258
class Cat extends Animal
1259
{
1260
    public static function loadMetadata(ClassMetadataInfo $metadata)
1261
    {
1262
1263
    }
1264
}
1265
1266
/** @Entity */
1267
class Dog extends Animal
1268
{
1269
    public static function loadMetadata(ClassMetadataInfo $metadata)
1270
    {
1271
1272
    }
1273
}
1274
1275
1276
/**
1277
 * @Entity
1278
 */
1279
class DDC1170Entity
1280
{
1281
1282
    /**
1283
     * @param string $value
1284
     */
1285
    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...
1286
    {
1287
        $this->value = $value;
1288
    }
1289
1290
    /**
1291
     * @Id
1292
     * @GeneratedValue(strategy="NONE")
1293
     * @Column(type="integer", columnDefinition = "INT unsigned NOT NULL")
1294
     **/
1295
    private $id;
1296
1297
    /**
1298
     * @Column(columnDefinition = "VARCHAR(255) NOT NULL")
1299
     */
1300
    private $value;
1301
1302
    /**
1303
     * @return int
1304
     */
1305
    public function getId()
1306
    {
1307
        return $this->id;
1308
    }
1309
1310
    /**
1311
     * @return string
1312
     */
1313
    public function getValue()
1314
    {
1315
        return $this->value;
1316
    }
1317
1318
    public static function loadMetadata(ClassMetadataInfo $metadata)
1319
    {
1320
        $metadata->mapField(array(
1321
           'id'                 => true,
1322
           'fieldName'          => 'id',
1323
           'columnDefinition'   => 'INT unsigned NOT NULL',
1324
        ));
1325
1326
        $metadata->mapField(array(
1327
            'fieldName'         => 'value',
1328
            'columnDefinition'  => 'VARCHAR(255) NOT NULL'
1329
        ));
1330
1331
        $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE);
1332
    }
1333
1334
}
1335
1336
/**
1337
 * @Entity
1338
 * @InheritanceType("SINGLE_TABLE")
1339
 * @DiscriminatorMap({"ONE" = "DDC807SubClasse1", "TWO" = "DDC807SubClasse2"})
1340
 * @DiscriminatorColumn(name = "dtype", columnDefinition="ENUM('ONE','TWO')")
1341
 */
1342
class DDC807Entity
1343
{
1344
    /**
1345
     * @Id
1346
     * @Column(type="integer")
1347
     * @GeneratedValue(strategy="NONE")
1348
     **/
1349
   public $id;
1350
1351
   public static function loadMetadata(ClassMetadataInfo $metadata)
1352
    {
1353
         $metadata->mapField(array(
1354
           'id'                 => true,
1355
           'fieldName'          => 'id',
1356
        ));
1357
1358
        $metadata->setDiscriminatorColumn(array(
1359
            'name'              => "dtype",
1360
            'type'              => "string",
1361
            'columnDefinition'  => "ENUM('ONE','TWO')"
1362
        ));
1363
1364
        $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE);
1365
    }
1366
}
1367
1368
class DDC807SubClasse1 {}
1369
class DDC807SubClasse2 {}
1370
1371
class Address {}
1372
class Phonenumber {}
1373
class Group {}
1374
1375
/**
1376
 * @Entity
1377
 * @Table(indexes={@Index(columns={"content"}, flags={"fulltext"}, options={"where": "content IS NOT NULL"})})
1378
 */
1379
class Comment
1380
{
1381
    /**
1382
     * @Column(type="text")
1383
     */
1384
    private $content;
1385
1386
    public static function loadMetadata(ClassMetadataInfo $metadata)
1387
    {
1388
        $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
1389
        $metadata->setPrimaryTable(array(
1390
            'indexes' => array(
1391
                array('columns' => array('content'), 'flags' => array('fulltext'), 'options' => array('where' => 'content IS NOT NULL'))
1392
            )
1393
        ));
1394
1395
        $metadata->mapField(array(
1396
            'fieldName' => 'content',
1397
            'type' => 'text',
1398
            'scale' => 0,
1399
            'length' => NULL,
1400
            'unique' => false,
1401
            'nullable' => false,
1402
            'precision' => 0,
1403
            'columnName' => 'content',
1404
        ));
1405
    }
1406
}
1407
1408
/**
1409
 * @Entity
1410
 * @InheritanceType("SINGLE_TABLE")
1411
 * @DiscriminatorMap({
1412
 *     "ONE" = "SingleTableEntityNoDiscriminatorColumnMappingSub1",
1413
 *     "TWO" = "SingleTableEntityNoDiscriminatorColumnMappingSub2"
1414
 * })
1415
 */
1416
class SingleTableEntityNoDiscriminatorColumnMapping
1417
{
1418
    /**
1419
     * @Id
1420
     * @Column(type="integer")
1421
     * @GeneratedValue(strategy="NONE")
1422
     */
1423
    public $id;
1424
1425
    public static function loadMetadata(ClassMetadataInfo $metadata)
1426
    {
1427
        $metadata->mapField(array(
1428
            'id' => true,
1429
            'fieldName' => 'id',
1430
        ));
1431
1432
        $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE);
1433
    }
1434
}
1435
1436
class SingleTableEntityNoDiscriminatorColumnMappingSub1 extends SingleTableEntityNoDiscriminatorColumnMapping {}
1437
class SingleTableEntityNoDiscriminatorColumnMappingSub2 extends SingleTableEntityNoDiscriminatorColumnMapping {}
1438
1439
/**
1440
 * @Entity
1441
 * @InheritanceType("SINGLE_TABLE")
1442
 * @DiscriminatorMap({
1443
 *     "ONE" = "SingleTableEntityIncompleteDiscriminatorColumnMappingSub1",
1444
 *     "TWO" = "SingleTableEntityIncompleteDiscriminatorColumnMappingSub2"
1445
 * })
1446
 * @DiscriminatorColumn(name="dtype")
1447
 */
1448
class SingleTableEntityIncompleteDiscriminatorColumnMapping
1449
{
1450
    /**
1451
     * @Id
1452
     * @Column(type="integer")
1453
     * @GeneratedValue(strategy="NONE")
1454
     */
1455
    public $id;
1456
1457
    public static function loadMetadata(ClassMetadataInfo $metadata)
1458
    {
1459
        $metadata->mapField(array(
1460
            'id' => true,
1461
            'fieldName' => 'id',
1462
        ));
1463
1464
        $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE);
1465
    }
1466
}
1467
1468
class SingleTableEntityIncompleteDiscriminatorColumnMappingSub1
1469
    extends SingleTableEntityIncompleteDiscriminatorColumnMapping {}
1470
class SingleTableEntityIncompleteDiscriminatorColumnMappingSub2
1471
    extends SingleTableEntityIncompleteDiscriminatorColumnMapping {}