Failed Conditions
Push — master ( 6d428c...2a5864 )
by Marco
165:30 queued 100:26
created

DDC6499Test   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 50.82 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 31
loc 61
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 9 1
A tearDown() 0 9 1
A testIssue() 16 16 1
A testIssueReversed() 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\Functional\Ticket;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\Tests\OrmFunctionalTestCase;
7
8
/**
9
 * @group #6499
10
 *
11
 *
12
 * Specifically, DDC6499B has a dependency on DDC6499A, and DDC6499A
13
 * has a dependency on DDC6499B. Since DDC6499A#b is not nullable,
14
 * the DDC6499B should be inserted first.
15
 */
16
class DDC6499Test extends OrmFunctionalTestCase
17
{
18
    /**
19
     * {@inheritDoc}
20
     */
21
    protected function setUp() : void
22
    {
23
        parent::setUp();
24
25
        $this->_schemaTool->createSchema([
26
            $this->_em->getClassMetadata(DDC6499A::class),
27
            $this->_em->getClassMetadata(DDC6499B::class),
28
        ]);
29
    }
30
31
    /**
32
     * {@inheritDoc}
33
     */
34
    protected function tearDown() : void
35
    {
36
        parent::tearDown();
37
38
        $this->_schemaTool->dropSchema([
39
            $this->_em->getClassMetadata(DDC6499A::class),
40
            $this->_em->getClassMetadata(DDC6499B::class),
41
        ]);
42
    }
43
44 View Code Duplication
    public function testIssue() : void
45
    {
46
        $b = new DDC6499B();
47
        $a = new DDC6499A();
48
49
        $this->_em->persist($a);
50
51
        $a->b = $b;
52
53
        $this->_em->persist($b);
54
55
        $this->_em->flush();
56
57
        self::assertInternalType('integer', $a->id);
58
        self::assertInternalType('integer', $b->id);
59
    }
60
61 View Code Duplication
    public function testIssueReversed() : void
62
    {
63
        $b = new DDC6499B();
64
        $a = new DDC6499A();
65
66
        $a->b = $b;
67
68
        $this->_em->persist($b);
69
        $this->_em->persist($a);
70
71
        $this->_em->flush();
72
73
        self::assertInternalType('integer', $a->id);
74
        self::assertInternalType('integer', $b->id);
75
    }
76
}
77
78
/** @Entity */
79
class DDC6499A
80
{
81
    /** @Id @Column(type="integer") @GeneratedValue */
82
    public $id;
83
84
    /** @JoinColumn(nullable=false) @OneToOne(targetEntity=DDC6499B::class) */
85
    public $b;
86
}
87
88
/** @Entity */
89
class DDC6499B
90
{
91
    /** @Id @Column(type="integer") @GeneratedValue */
92
    public $id;
93
94
    /** @ManyToOne(targetEntity="DDC6499A") */
95
    private $a;
96
}
97