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

Ticket4646InstanceOfTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testInstanceOf() 14 14 1
A setUp() 9 9 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 Ticket4646InstanceOfTest 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(PersonTicket4646::class),
15
            $this->_em->getClassMetadata(EmployeeTicket4646::class),
16
        ]);
17
    }
18
19
    public function testInstanceOf()
20
    {
21
        $this->_em->persist(new PersonTicket4646());
22
        $this->_em->persist(new EmployeeTicket4646());
23
        $this->_em->flush();
24
25
        $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646 p
26
                WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646';
27
        $query = $this->_em->createQuery($dql);
28
        $result = $query->getResult();
29
30
        $this->assertCount(2, $result);
31
        $this->assertContainsOnlyInstancesOf(PersonTicket4646::class, $result);
32
    }
33
}
34
35
/**
36
 * @Entity()
37
 * @Table(name="instance_of_test_person")
38
 * @InheritanceType(value="JOINED")
39
 * @DiscriminatorColumn(name="kind", type="string")
40
 * @DiscriminatorMap(value={
41
 *     "person": "Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646",
42
 *     "employee": "Doctrine\Tests\ORM\Functional\Ticket\EmployeeTicket4646"
43
 * })
44
 */
45
class PersonTicket4646
46
{
47
    /**
48
     * @Id()
49
     * @GeneratedValue()
50
     * @Column(type="integer")
51
     */
52
    private $id;
53
54
    public function getId()
55
    {
56
        return $this->id;
57
    }
58
}
59
60
/**
61
 * @Entity()
62
 * @Table(name="instance_of_test_employee")
63
 */
64
class EmployeeTicket4646 extends PersonTicket4646
65
{
66
}
67