StoreDocumentBench   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 88
Duplicated Lines 29.55 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 6
dl 26
loc 88
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A benchStoreDocument() 0 10 1
A benchStoreDocumentWithEmbedOne() 0 15 1
A benchStoreDocumentWithEmbedMany() 12 12 1
A benchStoreDocumentWithReferenceOne() 14 14 1
A benchStoreDocumentWithReferenceMany() 0 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
declare(strict_types=1);
4
5
namespace Doctrine\ODM\MongoDB\Benchmark\Document;
6
7
use DateTimeImmutable;
8
use Doctrine\ODM\MongoDB\Benchmark\BaseBench;
9
use Documents\Account;
10
use Documents\Address;
11
use Documents\Group;
12
use Documents\Phonenumber;
13
use Documents\User;
14
use PhpBench\Benchmark\Metadata\Annotations\Warmup;
15
16
final class StoreDocumentBench extends BaseBench
17
{
18
    /**
19
     * @Warmup(2)
20
     */
21
    public function benchStoreDocument()
22
    {
23
        $user = new User();
24
        $user->setUsername('alcaeus');
25
        $user->setCreatedAt(new DateTimeImmutable());
0 ignored issues
show
Bug introduced by
The method setCreatedAt() does not seem to exist on object<Documents\User>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
26
27
        $this->getDocumentManager()->persist($user);
28
        $this->getDocumentManager()->flush();
29
        $this->getDocumentManager()->clear();
30
    }
31
32
    /**
33
     * @Warmup(2)
34
     */
35
    public function benchStoreDocumentWithEmbedOne()
36
    {
37
        $address = new Address();
38
        $address->setAddress('Redacted');
0 ignored issues
show
Bug introduced by
The method setAddress() does not seem to exist on object<Documents\Address>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
        $address->setCity('Munich');
40
41
        $user = new User();
42
        $user->setUsername('alcaeus');
43
        $user->setCreatedAt(new DateTimeImmutable());
0 ignored issues
show
Bug introduced by
The method setCreatedAt() does not seem to exist on object<Documents\User>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
        $user->setAddress($address);
45
46
        $this->getDocumentManager()->persist($user);
47
        $this->getDocumentManager()->flush();
48
        $this->getDocumentManager()->clear();
49
    }
50
51
    /**
52
     * @Warmup(2)
53
     */
54 View Code Duplication
    public function benchStoreDocumentWithEmbedMany()
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
        $user = new User();
57
        $user->setUsername('alcaeus');
58
        $user->setCreatedAt(new DateTimeImmutable());
0 ignored issues
show
Bug introduced by
The method setCreatedAt() does not seem to exist on object<Documents\User>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
59
        $user->addPhonenumber(new Phonenumber('12345678'));
60
        $user->addPhonenumber(new Phonenumber('12345678'));
61
62
        $this->getDocumentManager()->persist($user);
63
        $this->getDocumentManager()->flush();
64
        $this->getDocumentManager()->clear();
65
    }
66
67
    /**
68
     * @Warmup(2)
69
     */
70 View Code Duplication
    public function benchStoreDocumentWithReferenceOne()
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...
71
    {
72
        $account = new Account();
0 ignored issues
show
Bug introduced by
The call to Account::__construct() misses a required argument $name.

This check looks for function calls that miss required arguments.

Loading history...
73
        $account->setName('alcaeus');
74
75
        $user = new User();
76
        $user->setUsername('alcaeus');
77
        $user->setCreatedAt(new DateTimeImmutable());
0 ignored issues
show
Bug introduced by
The method setCreatedAt() does not seem to exist on object<Documents\User>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
78
        $user->setAccount($account);
79
80
        $this->getDocumentManager()->persist($user);
81
        $this->getDocumentManager()->flush();
82
        $this->getDocumentManager()->clear();
83
    }
84
85
    /**
86
     * @Warmup(2)
87
     */
88
    public function benchStoreDocumentWithReferenceMany()
89
    {
90
        $group1 = new Group('One');
91
        $group2 = new Group('Two');
92
93
        $user = new User();
94
        $user->setUsername('alcaeus');
95
        $user->setCreatedAt(new DateTimeImmutable());
0 ignored issues
show
Bug introduced by
The method setCreatedAt() does not seem to exist on object<Documents\User>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
96
        $user->addGroup($group1);
0 ignored issues
show
Bug introduced by
The method addGroup() does not seem to exist on object<Documents\User>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
97
        $user->addGroup($group2);
0 ignored issues
show
Bug introduced by
The method addGroup() does not seem to exist on object<Documents\User>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
98
99
        $this->getDocumentManager()->persist($user);
100
        $this->getDocumentManager()->flush();
101
        $this->getDocumentManager()->clear();
102
    }
103
}
104