Failed Conditions
Pull Request — master (#6575)
by Luís
14:40
created

init()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 53
Code Lines 39

Duplication

Lines 53
Ratio 100 %

Importance

Changes 0
Metric Value
dl 53
loc 53
rs 9.5797
c 0
b 0
f 0
cc 2
eloc 39
nc 2
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Doctrine\Performance\Hydration;
4
5
use Doctrine\ORM\Internal\Hydration\ObjectHydrator;
6
use Doctrine\ORM\Query;
7
use Doctrine\ORM\Query\ResultSetMapping;
8
use Doctrine\Performance\EntityManagerFactory;
9
use Doctrine\Tests\Mocks\HydratorMockStatement;
10
use Doctrine\Tests\Models\CMS\CmsPhonenumber;
11
use Doctrine\Tests\Models\CMS\CmsUser;
12
use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods;
13
14
/**
15
 * @BeforeMethods({"init"})
16
 */
17 View Code Duplication
final class MixedQueryFetchJoinPartialObjectHydrationPerformanceBench
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...
18
{
19
    /**
20
     * @var ObjectHydrator
21
     */
22
    private $hydrator;
23
24
    /**
25
     * @var ResultSetMapping
26
     */
27
    private $rsm;
28
29
    /**
30
     * @var HydratorMockStatement
31
     */
32
    private $stmt;
33
34
    public function init()
35
    {
36
        $resultSet = [
37
            [
38
                'u__id'          => '1',
39
                'u__status'      => 'developer',
40
                'u__username'    => 'romanb',
41
                'u__name'        => 'Roman',
42
                'sclr0'          => 'ROMANB',
43
                'p__phonenumber' => '42',
44
            ],
45
            [
46
                'u__id'          => '1',
47
                'u__status'      => 'developer',
48
                'u__username'    => 'romanb',
49
                'u__name'        => 'Roman',
50
                'sclr0'          => 'ROMANB',
51
                'p__phonenumber' => '43',
52
            ],
53
            [
54
                'u__id'          => '2',
55
                'u__status'      => 'developer',
56
                'u__username'    => 'romanb',
57
                'u__name'        => 'Roman',
58
                'sclr0'          => 'JWAGE',
59
                'p__phonenumber' => '91'
60
            ]
61
        ];
62
63
        for ($i = 4; $i < 2000; ++$i) {
64
            $resultSet[] = [
65
                'u__id'          => $i,
66
                'u__status'      => 'developer',
67
                'u__username'    => 'jwage',
68
                'u__name'        => 'Jonathan',
69
                'sclr0'          => 'JWAGE' . $i,
70
                'p__phonenumber' => '91'
71
            ];
72
        }
73
74
        $this->stmt     = new HydratorMockStatement($resultSet);
75
        $this->hydrator = new ObjectHydrator(EntityManagerFactory::getEntityManager([]));
76
        $this->rsm      = new ResultSetMapping;
77
78
        $this->rsm->addEntityResult(CmsUser::class, 'u');
79
        $this->rsm->addJoinedEntityResult(CmsPhonenumber::class, 'p', 'u', 'phonenumbers');
80
        $this->rsm->addFieldResult('u', 'u__id', 'id');
81
        $this->rsm->addFieldResult('u', 'u__status', 'status');
82
        $this->rsm->addFieldResult('u', 'u__username', 'username');
83
        $this->rsm->addFieldResult('u', 'u__name', 'name');
84
        $this->rsm->addScalarResult('sclr0', 'nameUpper');
85
        $this->rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber');
86
    }
87
88
    public function benchHydration()
89
    {
90
        $this->hydrator->hydrateAll($this->stmt, $this->rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]);
91
    }
92
}
93
94