Completed
Pull Request — master (#42)
by Daniel
04:11
created

DoctrineOrmBench   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 100
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 46 46 1
A image_phpcr_odm_only() 11 11 1
A ct_article() 11 11 1
A ct_article_with_image() 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 Psi\Component\ContentType\Benchmark;
4
5
use Psi\Bridge\ContentType\Doctrine\OrmOdm\Tests\Functional\OrmOdmTestCase;
6
use Psi\Component\ContentType\Tests\Functional\Example\Model\Image;
7
use Psi\Bridge\ContentType\Doctrine\Orm\Tests\Functional\OrmTestCase;
8
use Psi\Component\ContentType\Tests\Functional\Example\Model\Article;
9
10
/**
11
 * @BeforeMethods({"setUp"})
12
 * @Revs(1)
13
 * @Iterations(10)
14
 * @OutputTimeUnit("milliseconds", precision=2)
15
 */
16 View Code Duplication
class DoctrineOrmBench extends OrmTestCase
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...
17
{
18
    private $entityManager;
19
20
    public function setUp()
21
    {
22
        $container = $this->getContainer([
23
            'mapping' => [
24
                Article::class => [
25
                    'properties' => [
26
                        'title' => [
27
                            'type' => 'text',
28
                            'role' => 'title',
29
                        ],
30
                        'image' => [
31
                            'type' => 'image',
32
                            'role' => 'image',
33
                        ],
34
                        'slideshow' => [
35
                            'type' => 'collection',
36
                            'options' => [
37
                                'field_type' => 'image',
38
                            ],
39
                        ],
40
                        'date' => [
41
                            'type' => 'datetime',
42
                        ],
43
                        'referencedImage' => [
44
                            'type' => 'object_reference',
45
                        ],
46
                        'paragraphs' => [
47
                            'type' => 'collection',
48
                            'options' => [
49
                                'field_type' => 'text',
50
                                'field_options' => [],
51
                            ],
52
                        ],
53
                        'numbers' => [
54
                            'type' => 'collection',
55
                            'options' => [
56
                                'field_type' => 'integer',
57
                            ],
58
                        ],
59
                    ],
60
                ],
61
            ],
62
        ]);
63
        $this->entityManager = $container->get('doctrine.entity_manager');
64
        $this->initOrm($this->entityManager);
65
    }
66
67
    /**
68
     * @Subject()
69
     */
70
    public function image_phpcr_odm_only()
71
    {
72
        static $id;
73
        $image = new Image(
74
            '/path/to/image', 100, 200, 'image/jpeg'
75
        );
76
        $image->id = '/test/image' . $id++;
77
78
        $this->entityManager->persist($image);
79
        $this->entityManager->flush();
80
    }
81
82
    /**
83
     * @Subject()
84
     */
85
    public function ct_article()
86
    {
87
        static $id;
88
        $article = new Article();
89
        $article->id = '/test/article' . $id++;
90
        $article->title = 'Hello';
91
        $article->date = new \DateTime('2016-01-01 00:00:00');
92
93
        $this->entityManager->persist($article);
94
        $this->entityManager->flush();
95
    }
96
97
    /**
98
     * @Subject()
99
     */
100
    public function ct_article_with_image()
101
    {
102
        static $id;
103
        $article = new Article();
104
        $article->id = '/test/article' . $id++;
105
        $article->title = 'Hello';
106
        $article->date = new \DateTime('2016-01-01 00:00:00');
107
108
        $article->image = new Image(
109
            '/path/to/image', 100, 200, 'image/jpeg'
110
        );
111
112
        $this->entityManager->persist($article);
113
        $this->entityManager->flush();
114
    }
115
}
116