InheritenceTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 96
Duplicated Lines 93.75 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 90
loc 96
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testPersistInheritanceReferenceOne() 19 19 1
A testPersistInheritanceReferenceMany() 26 26 1
A testPersistInheritanceEmbededOne() 19 19 1
A testPersistInheritanceEmbedMany() 26 26 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\ODM\CouchDB\Functional;
4
5
class InheritenceTest extends \Doctrine\Tests\ODM\CouchDB\CouchDBFunctionalTestCase
6
{
7 View Code Duplication
    public function testPersistInheritanceReferenceOne()
0 ignored issues
show
Duplication introduced by
This method 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
        $child = new CODM25ChildA();
10
        $child->foo = "bar";
11
        $parent = new CODM25Parent();
12
        $parent->child = $child;
13
14
        $dm = $this->createDocumentManager();
15
        $dm->persist($parent);
16
        $dm->persist($parent->child);
17
        $dm->flush();
18
19
        $dm->clear();
20
21
        $parent = $dm->find(__NAMESPACE__ . '\\CODM25Parent', $parent->id);
22
23
        $this->assertInstanceOf(__NAMESPACE__ . '\\CODM25ChildA', $parent->child);
24
        $this->assertEquals('bar', $parent->child->foo);
25
    }
26
27 View Code Duplication
    public function testPersistInheritanceReferenceMany()
0 ignored issues
show
Duplication introduced by
This method 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...
28
    {
29
        $child1 = new CODM25ChildA();
30
        $child1->foo = "bar";
31
        $child2 = new CODM25ChildA();
32
        $child2->foo = "baz";
33
        $parent = new CODM25Parent();
34
        $parent->childs[] = $child1;
35
        $parent->childs[] = $child2;
36
37
        $dm = $this->createDocumentManager();
38
        $dm->persist($parent);
39
        $dm->persist($parent->childs[0]);
40
        $dm->persist($parent->childs[1]);
41
        $dm->flush();
42
43
        $dm->clear();
44
45
        $parent = $dm->find(__NAMESPACE__ . '\\CODM25Parent', $parent->id);
46
47
        $this->assertCount(2, $parent->childs);
48
        $this->assertInstanceOf(__NAMESPACE__ . '\\CODM25ChildA', $parent->childs[0]);
49
        $this->assertEquals('bar', $parent->childs[0]->foo);
50
        $this->assertInstanceOf(__NAMESPACE__ . '\\CODM25ChildA', $parent->childs[1]);
51
        $this->assertEquals('baz', $parent->childs[1]->foo);
52
    }
53
54 View Code Duplication
    public function testPersistInheritanceEmbededOne()
0 ignored issues
show
Duplication introduced by
This method 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...
55
    {
56
        $child = new CODM25ChildA();
57
        $child->foo = "bar";
58
        $parent = new CODM25Parent();
59
        $parent->embed = $child;
60
61
        $dm = $this->createDocumentManager();
62
        $dm->persist($parent);
63
        $dm->persist($parent->embed);
64
        $dm->flush();
65
66
        $dm->clear();
67
68
        $parent = $dm->find(__NAMESPACE__ . '\\CODM25Parent', $parent->id);
69
70
        $this->assertInstanceOf(__NAMESPACE__ . '\\CODM25ChildA', $parent->embed);
71
        $this->assertEquals('bar', $parent->embed->foo);
72
    }
73
74 View Code Duplication
    public function testPersistInheritanceEmbedMany()
0 ignored issues
show
Duplication introduced by
This method 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...
75
    {
76
        $child1 = new CODM25ChildA();
77
        $child1->foo = "bar";
78
        $child2 = new CODM25ChildA();
79
        $child2->foo = "baz";
80
        $parent = new CODM25Parent();
81
        $parent->embeds[] = $child1;
82
        $parent->embeds[] = $child2;
83
84
        $dm = $this->createDocumentManager();
85
        $dm->persist($parent);
86
        $dm->persist($parent->embeds[0]);
87
        $dm->persist($parent->embeds[1]);
88
        $dm->flush();
89
90
        $dm->clear();
91
92
        $parent = $dm->find(__NAMESPACE__ . '\\CODM25Parent', $parent->id);
93
94
        $this->assertCount(2, $parent->embeds);
95
        $this->assertInstanceOf(__NAMESPACE__ . '\\CODM25ChildA', $parent->embeds[0]);
96
        $this->assertEquals('bar', $parent->embeds[0]->foo);
97
        $this->assertInstanceOf(__NAMESPACE__ . '\\CODM25ChildA', $parent->embeds[1]);
98
        $this->assertEquals('baz', $parent->embeds[1]->foo);
99
    }
100
}
101
102
/**
103
 * @Document
104
 */
105
class CODM25Parent
106
{
107
    /** @Id */
108
    public $id;
109
110
    /** @ReferenceOne(targetDocument="CODM25Child") */
111
    public $child;
112
113
    /** @ReferenceMany(targetDocument="CODM25Child") */
114
    public $childs;
115
116
    /**
117
     * @EmbedOne(targetDocument="CODM25Child")
118
     */
119
    public $embed;
120
121
    /**
122
     * @EmbedMany(targetDocument="CODM25Child")
123
     */
124
    public $embeds;
125
}
126
127
/**
128
 * @Document
129
 * @InheritanceRoot
130
 */
131
abstract class CODM25Child
132
{
133
    /** @Id */
134
    public $id;
135
}
136
137
/**
138
 * @Document
139
 */
140
class CODM25ChildA extends CODM25Child
141
{
142
    /** @Field */
143
    public $foo;
144
}
145