Failed Conditions
Pull Request — master (#6392)
by Alessandro
18:37
created

Ticket4646InstanceOfMultiLevelTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 7
dl 29
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 10 10 1
A testInstanceOf() 15 15 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5
use Doctrine\Tests\OrmFunctionalTestCase;
6
7 View Code Duplication
class Ticket4646InstanceOfMultiLevelTest extends OrmFunctionalTestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
{
9
    protected function setUp()
10
    {
11
        parent::setUp();
12
13
        $this->_schemaTool->createSchema([
14
            $this->_em->getClassMetadata(PersonTicket4646MultiLevel::class),
15
            $this->_em->getClassMetadata(EmployeeTicket4646MultiLevel::class),
16
            $this->_em->getClassMetadata(EngineerTicket4646MultiLevel::class),
17
        ]);
18
    }
19
20
    public function testInstanceOf()
21
    {
22
        $this->_em->persist(new PersonTicket4646MultiLevel());
23
        $this->_em->persist(new EmployeeTicket4646MultiLevel());
24
        $this->_em->persist(new EngineerTicket4646MultiLevel());
25
        $this->_em->flush();
26
27
        $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646MultiLevel p
28
                WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646MultiLevel';
29
        $query = $this->_em->createQuery($dql);
30
        $result = $query->getResult();
31
32
        $this->assertCount(3, $result);
33
        $this->assertContainsOnlyInstancesOf(PersonTicket4646MultiLevel::class, $result);
34
    }
35
}
36
37
/**
38
 * @Entity()
39
 * @Table(name="instance_of_multi_level_test_person")
40
 * @InheritanceType(value="JOINED")
41
 * @DiscriminatorColumn(name="kind", type="string")
42
 * @DiscriminatorMap(value={
43
 *     "person": "Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646MultiLevel",
44
 *     "employee": "Doctrine\Tests\ORM\Functional\Ticket\EmployeeTicket4646MultiLevel",
45
 *     "engineer": "Doctrine\Tests\ORM\Functional\Ticket\EngineerTicket4646MultiLevel",
46
 * })
47
 */
48
class PersonTicket4646MultiLevel
49
{
50
    /**
51
     * @Id()
52
     * @GeneratedValue()
53
     * @Column(type="integer")
54
     */
55
    private $id;
56
57
    public function getId()
58
    {
59
        return $this->id;
60
    }
61
}
62
63
/**
64
 * @Entity()
65
 * @Table(name="instance_of_multi_level_employee")
66
 */
67
class EmployeeTicket4646MultiLevel extends PersonTicket4646MultiLevel
68
{
69
}
70
71
/**
72
 * @Entity()
73
 * @Table(name="instance_of_multi_level_engineer")
74
 */
75
class EngineerTicket4646MultiLevel extends EmployeeTicket4646MultiLevel
76
{
77
}
78