Completed
Pull Request — master (#1620)
by Maciej
09:27
created

HydratorFactory::hydrate()   C

Complexity

Conditions 12
Paths 64

Size

Total Lines 49
Code Lines 27

Duplication

Lines 9
Ratio 18.37 %

Code Coverage

Tests 27
CRAP Score 12

Importance

Changes 0
Metric Value
dl 9
loc 49
ccs 27
cts 27
cp 1
rs 5.1474
c 0
b 0
f 0
cc 12
eloc 27
nc 64
nop 3
crap 12

How to fix   Complexity   

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
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Doctrine\ODM\MongoDB\Hydrator;
21
22
use Doctrine\Common\EventManager;
23
use Doctrine\ODM\MongoDB\DocumentManager;
24
use Doctrine\ODM\MongoDB\Event\LifecycleEventArgs;
25
use Doctrine\ODM\MongoDB\Event\PreLoadEventArgs;
26
use Doctrine\ODM\MongoDB\Events;
27
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
28
use Doctrine\ODM\MongoDB\Proxy\Proxy;
29
use Doctrine\ODM\MongoDB\Types\Type;
30
use Doctrine\ODM\MongoDB\UnitOfWork;
31
use Doctrine\ODM\MongoDB\Configuration;
32
33
/**
34
 * The HydratorFactory class is responsible for instantiating a correct hydrator
35
 * type based on document's ClassMetadata
36
 *
37
 * @since       1.0
38
 */
39
class HydratorFactory
40
{
41
    /**
42
     * The DocumentManager this factory is bound to.
43
     *
44
     * @var \Doctrine\ODM\MongoDB\DocumentManager
45
     */
46
    private $dm;
47
48
    /**
49
     * The UnitOfWork used to coordinate object-level transactions.
50
     *
51
     * @var \Doctrine\ODM\MongoDB\UnitOfWork
52
     */
53
    private $unitOfWork;
54
55
    /**
56
     * The EventManager associated with this Hydrator
57
     *
58
     * @var \Doctrine\Common\EventManager
59
     */
60
    private $evm;
61
62
    /**
63
     * Which algorithm to use to automatically (re)generate hydrator classes.
64
     *
65
     * @var integer
66
     */
67
    private $autoGenerate;
68
69
    /**
70
     * The namespace that contains all hydrator classes.
71
     *
72
     * @var string
73
     */
74
    private $hydratorNamespace;
75
76
    /**
77
     * The directory that contains all hydrator classes.
78
     *
79
     * @var string
80
     */
81
    private $hydratorDir;
82
83
    /**
84
     * Array of instantiated document hydrators.
85
     *
86
     * @var array
87
     */
88
    private $hydrators = array();
89
90
    /**
91
     * @param DocumentManager $dm
92
     * @param EventManager $evm
93
     * @param string $hydratorDir
94
     * @param string $hydratorNs
95
     * @param integer $autoGenerate
96
     * @throws HydratorException
97
     */
98 1130
    public function __construct(DocumentManager $dm, EventManager $evm, $hydratorDir, $hydratorNs, $autoGenerate)
99
    {
100 1130
        if ( ! $hydratorDir) {
101
            throw HydratorException::hydratorDirectoryRequired();
102
        }
103 1130
        if ( ! $hydratorNs) {
104
            throw HydratorException::hydratorNamespaceRequired();
105
        }
106 1130
        $this->dm = $dm;
107 1130
        $this->evm = $evm;
108 1130
        $this->hydratorDir = $hydratorDir;
109 1130
        $this->hydratorNamespace = $hydratorNs;
110 1130
        $this->autoGenerate = $autoGenerate;
111 1130
    }
112
113
    /**
114
     * Sets the UnitOfWork instance.
115
     *
116
     * @param UnitOfWork $uow
117
     */
118 1130
    public function setUnitOfWork(UnitOfWork $uow)
119
    {
120 1130
        $this->unitOfWork = $uow;
121 1130
    }
122
123
    /**
124
     * Gets the hydrator object for the given document class.
125
     *
126
     * @param string $className
127
     * @return \Doctrine\ODM\MongoDB\Hydrator\HydratorInterface $hydrator
128
     */
129 412
    public function getHydratorFor($className)
130
    {
131 412
        if (isset($this->hydrators[$className])) {
132 211
            return $this->hydrators[$className];
133
        }
134 412
        $hydratorClassName = str_replace('\\', '', $className) . 'Hydrator';
135 412
        $fqn = $this->hydratorNamespace . '\\' . $hydratorClassName;
136 412
        $class = $this->dm->getClassMetadata($className);
137
138 412 View Code Duplication
        if ( ! class_exists($fqn, false)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
139 182
            $fileName = $this->hydratorDir . DIRECTORY_SEPARATOR . $hydratorClassName . '.php';
140 182
            switch ($this->autoGenerate) {
141
                case Configuration::AUTOGENERATE_NEVER:
142
                    require $fileName;
143
                    break;
144
                    
145
                case Configuration::AUTOGENERATE_ALWAYS:
146 182
                    $this->generateHydratorClass($class, $hydratorClassName, $fileName);
147 182
                    require $fileName;
148 182
                    break;
149
                    
150
                case Configuration::AUTOGENERATE_FILE_NOT_EXISTS:
151
                    if (!file_exists($fileName)) {
152
                        $this->generateHydratorClass($class, $hydratorClassName, $fileName);
153
                    }
154
                    require $fileName;
155
                    break;
156
                    
157
                case Configuration::AUTOGENERATE_EVAL:
158
                    $this->generateHydratorClass($class, $hydratorClassName, false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
159
                    break;
160
            }
161
        }
162 412
        $this->hydrators[$className] = new $fqn($this->dm, $this->unitOfWork, $class);
163 412
        return $this->hydrators[$className];
164
    }
165
166
    /**
167
     * Generates hydrator classes for all given classes.
168
     *
169
     * @param array $classes The classes (ClassMetadata instances) for which to generate hydrators.
170
     * @param string $toDir The target directory of the hydrator classes. If not specified, the
171
     *                      directory configured on the Configuration of the DocumentManager used
172
     *                      by this factory is used.
173
     */
174
    public function generateHydratorClasses(array $classes, $toDir = null)
175
    {
176
        $hydratorDir = $toDir ?: $this->hydratorDir;
177
        $hydratorDir = rtrim($hydratorDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
178
        foreach ($classes as $class) {
179
            $hydratorClassName = str_replace('\\', '', $class->name) . 'Hydrator';
180
            $hydratorFileName = $hydratorDir . $hydratorClassName . '.php';
181
            $this->generateHydratorClass($class, $hydratorClassName, $hydratorFileName);
182
        }
183
    }
184
185
    /**
186
     * @param ClassMetadata $class
187
     * @param string $hydratorClassName
188
     * @param string $fileName
189
     */
190 182
    private function generateHydratorClass(ClassMetadata $class, $hydratorClassName, $fileName)
191
    {
192 182
        $code = '';
193
194 182
        foreach ($class->fieldMappings as $fieldName => $mapping) {
195 182
            if (isset($mapping['alsoLoadFields'])) {
196 5
                foreach ($mapping['alsoLoadFields'] as $name) {
197 5
                    $code .= sprintf(<<<EOF
198
199 5
        /** @AlsoLoad("$name") */
200 5
        if (!array_key_exists('%1\$s', \$data) && array_key_exists('$name', \$data)) {
201 5
            \$data['%1\$s'] = \$data['$name'];
202
        }
203
204
EOF
205
                        ,
206 5
                        $mapping['name']
207
                    );
208
                }
209
            }
210
211 182
            if ($mapping['type'] === 'date') {
212 9
                $code .= sprintf(<<<EOF
213
214
        /** @Field(type="date") */
215
        if (isset(\$data['%1\$s'])) {
216
            \$value = \$data['%1\$s'];
217
            %3\$s
218
            \$this->class->reflFields['%2\$s']->setValue(\$document, clone \$return);
219
            \$hydratedData['%2\$s'] = \$return;
220
        }
221
222
EOF
223
                    ,
224 9
                    $mapping['name'],
225 9
                    $mapping['fieldName'],
226 9
                    Type::getType($mapping['type'])->closureToPHP()
227
                );
228
229
230 182
            } elseif ( ! isset($mapping['association'])) {
231 182
                $code .= sprintf(<<<EOF
232
233 182
        /** @Field(type="{$mapping['type']}") */
234
        if (isset(\$data['%1\$s']) || (! empty(\$this->class->fieldMappings['%2\$s']['nullable']) && array_key_exists('%1\$s', \$data))) {
235
            \$value = \$data['%1\$s'];
236
            if (\$value !== null) {
237
                \$typeIdentifier = \$this->class->fieldMappings['%2\$s']['type'];
238
                %3\$s
239
            } else {
240
                \$return = null;
241
            }
242
            \$this->class->reflFields['%2\$s']->setValue(\$document, \$return);
243
            \$hydratedData['%2\$s'] = \$return;
244
        }
245
246
EOF
247
                    ,
248 182
                    $mapping['name'],
249 182
                    $mapping['fieldName'],
250 182
                    Type::getType($mapping['type'])->closureToPHP()
251
                );
252 122 View Code Duplication
            } elseif ($mapping['association'] === ClassMetadata::REFERENCE_ONE && $mapping['isOwningSide']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
253 50
                $code .= sprintf(<<<EOF
254
255
        /** @ReferenceOne */
256
        if (isset(\$data['%1\$s'])) {
257
            \$reference = \$data['%1\$s'];
258
            \$className = \$this->unitOfWork->getClassNameForAssociation(\$this->class->fieldMappings['%2\$s'], \$reference);
259
            \$mongoId = ClassMetadataInfo::getReferenceId(\$reference, \$this->class->fieldMappings['%2\$s']['storeAs']);
260
            \$targetMetadata = \$this->dm->getClassMetadata(\$className);
261
            \$id = \$targetMetadata->getPHPIdentifierValue(\$mongoId);
262
            \$return = \$this->dm->getReference(\$className, \$id);
263
            \$this->class->reflFields['%2\$s']->setValue(\$document, \$return);
264
            \$hydratedData['%2\$s'] = \$return;
265
        }
266
267
EOF
268
                    ,
269 50
                    $mapping['name'],
270 50
                    $mapping['fieldName']
271
                );
272 104
            } elseif ($mapping['association'] === ClassMetadata::REFERENCE_ONE && $mapping['isInverseSide']) {
273 6
                if (isset($mapping['repositoryMethod']) && $mapping['repositoryMethod']) {
274 1
                    $code .= sprintf(<<<EOF
275
276
        \$className = \$this->class->fieldMappings['%2\$s']['targetDocument'];
277
        \$return = \$this->dm->getRepository(\$className)->%3\$s(\$document);
278
        \$this->class->reflFields['%2\$s']->setValue(\$document, \$return);
279
        \$hydratedData['%2\$s'] = \$return;
280
281
EOF
282
                        ,
283 1
                        $mapping['name'],
284 1
                        $mapping['fieldName'],
285 1
                        $mapping['repositoryMethod']
286
                    );
287
                } else {
288 6
                    $code .= sprintf(<<<EOF
289
290
        \$mapping = \$this->class->fieldMappings['%2\$s'];
291
        \$className = \$mapping['targetDocument'];
292
        \$targetClass = \$this->dm->getClassMetadata(\$mapping['targetDocument']);
293
        \$mappedByMapping = \$targetClass->fieldMappings[\$mapping['mappedBy']];
294
        \$mappedByFieldName = ClassMetadataInfo::getReferenceFieldName(\$mappedByMapping['storeAs'], \$mapping['mappedBy']);
295
        \$criteria = array_merge(
296
            array(\$mappedByFieldName => \$data['_id']),
297
            isset(\$this->class->fieldMappings['%2\$s']['criteria']) ? \$this->class->fieldMappings['%2\$s']['criteria'] : array()
298
        );
299
        \$sort = isset(\$this->class->fieldMappings['%2\$s']['sort']) ? \$this->class->fieldMappings['%2\$s']['sort'] : array();
300
        \$return = \$this->unitOfWork->getDocumentPersister(\$className)->load(\$criteria, null, array(), 0, \$sort);
301
        \$this->class->reflFields['%2\$s']->setValue(\$document, \$return);
302
        \$hydratedData['%2\$s'] = \$return;
303
304
EOF
305
                        ,
306 6
                        $mapping['name'],
307 6
                        $mapping['fieldName']
308
                    );
309
                }
310 103 View Code Duplication
            } elseif ($mapping['association'] === ClassMetadata::REFERENCE_MANY || $mapping['association'] === ClassMetadata::EMBED_MANY) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
311 82
                $code .= sprintf(<<<EOF
312
313
        /** @Many */
314
        \$mongoData = isset(\$data['%1\$s']) ? \$data['%1\$s'] : null;
315
        \$return = \$this->dm->getConfiguration()->getPersistentCollectionFactory()->create(\$this->dm, \$this->class->fieldMappings['%2\$s']);
316
        \$return->setHints(\$hints);
317
        \$return->setOwner(\$document, \$this->class->fieldMappings['%2\$s']);
318
        \$return->setInitialized(false);
319
        if (\$mongoData) {
320
            \$return->setMongoData(\$mongoData);
321
        }
322
        \$this->class->reflFields['%2\$s']->setValue(\$document, \$return);
323
        \$hydratedData['%2\$s'] = \$return;
324
325
EOF
326
                    ,
327 82
                    $mapping['name'],
328 82
                    $mapping['fieldName']
329
                );
330 45
            } elseif ($mapping['association'] === ClassMetadata::EMBED_ONE) {
331 45
                $code .= sprintf(<<<EOF
332
333
        /** @EmbedOne */
334
        if (isset(\$data['%1\$s'])) {
335
            \$embeddedDocument = \$data['%1\$s'];
336
            \$className = \$this->unitOfWork->getClassNameForAssociation(\$this->class->fieldMappings['%2\$s'], \$embeddedDocument);
337
            \$embeddedMetadata = \$this->dm->getClassMetadata(\$className);
338
            \$return = \$embeddedMetadata->newInstance();
339
340
            \$this->unitOfWork->setParentAssociation(\$return, \$this->class->fieldMappings['%2\$s'], \$document, '%1\$s');
341
342
            \$embeddedData = \$this->dm->getHydratorFactory()->hydrate(\$return, \$embeddedDocument, \$hints);
343
            \$embeddedId = \$embeddedMetadata->identifier && isset(\$embeddedData[\$embeddedMetadata->identifier]) ? \$embeddedData[\$embeddedMetadata->identifier] : null;
344
345
            if (empty(\$hints[Query::HINT_READ_ONLY])) {
346
                \$this->unitOfWork->registerManaged(\$return, \$embeddedId, \$embeddedData);
347
            }
348
349
            \$this->class->reflFields['%2\$s']->setValue(\$document, \$return);
350
            \$hydratedData['%2\$s'] = \$return;
351
        }
352
353
EOF
354
                    ,
355 45
                    $mapping['name'],
356 182
                    $mapping['fieldName']
357
                );
358
            }
359
        }
360
361 182
        $namespace = $this->hydratorNamespace;
362 182
        $code = sprintf(<<<EOF
363
<?php
364
365 182
namespace $namespace;
366
367
use Doctrine\ODM\MongoDB\DocumentManager;
368
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
369
use Doctrine\ODM\MongoDB\Hydrator\HydratorInterface;
370
use Doctrine\ODM\MongoDB\Query\Query;
371
use Doctrine\ODM\MongoDB\UnitOfWork;
372
use Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo;
373
374
/**
375
 * THIS CLASS WAS GENERATED BY THE DOCTRINE ODM. DO NOT EDIT THIS FILE.
376
 */
377 182
class $hydratorClassName implements HydratorInterface
378
{
379
    private \$dm;
380
    private \$unitOfWork;
381
    private \$class;
382
383
    public function __construct(DocumentManager \$dm, UnitOfWork \$uow, ClassMetadata \$class)
384
    {
385
        \$this->dm = \$dm;
386
        \$this->unitOfWork = \$uow;
387
        \$this->class = \$class;
388
    }
389
390
    public function hydrate(\$document, \$data, array \$hints = array())
391
    {
392
        \$hydratedData = array();
393
%s        return \$hydratedData;
394
    }
395
}
396
EOF
397
            ,
398 182
            $code
399
        );
400
401 182
        if ($fileName === false) {
402
            if ( ! class_exists($namespace . '\\' . $hydratorClassName)) {
403
                eval(substr($code, 5));
404
            }
405 View Code Duplication
        } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
406 182
            $parentDirectory = dirname($fileName);
407
408 182
            if ( ! is_dir($parentDirectory) && (false === @mkdir($parentDirectory, 0775, true))) {
409
                throw HydratorException::hydratorDirectoryNotWritable();
410
            }
411
412 182
            if ( ! is_writable($parentDirectory)) {
413
                throw HydratorException::hydratorDirectoryNotWritable();
414
            }
415
416 182
            $tmpFileName = $fileName . '.' . uniqid('', true);
417 182
            file_put_contents($tmpFileName, $code);
418 182
            rename($tmpFileName, $fileName);
419 182
            chmod($fileName, 0664);
420
        }
421 182
    }
422
423
    /**
424
     * Hydrate array of MongoDB document data into the given document object.
425
     *
426
     * @param object $document  The document object to hydrate the data into.
427
     * @param array $data The array of document data.
428
     * @param array $hints Any hints to account for during reconstitution/lookup of the document.
429
     * @return array $values The array of hydrated values.
430
     */
431 412
    public function hydrate($document, $data, array $hints = array())
432
    {
433 412
        $metadata = $this->dm->getClassMetadata(get_class($document));
434
        // Invoke preLoad lifecycle events and listeners
435 412
        if ( ! empty($metadata->lifecycleCallbacks[Events::preLoad])) {
436 14
            $args = array(new PreLoadEventArgs($document, $this->dm, $data));
437 14
            $metadata->invokeLifecycleCallbacks(Events::preLoad, $document, $args);
438
        }
439 412 View Code Duplication
        if ($this->evm->hasListeners(Events::preLoad)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
440 3
            $this->evm->dispatchEvent(Events::preLoad, new PreLoadEventArgs($document, $this->dm, $data));
441
        }
442
443
        // alsoLoadMethods may transform the document before hydration
444 412
        if ( ! empty($metadata->alsoLoadMethods)) {
445 12
            foreach ($metadata->alsoLoadMethods as $method => $fieldNames) {
446 12
                foreach ($fieldNames as $fieldName) {
447
                    // Invoke the method only once for the first field we find
448 12
                    if (array_key_exists($fieldName, $data)) {
449 8
                        $document->$method($data[$fieldName]);
450 12
                        continue 2;
451
                    }
452
                }
453
            }
454
        }
455
456 412
        $data = $this->getHydratorFor($metadata->name)->hydrate($document, $data, $hints);
457 412
        if ($document instanceof Proxy) {
458 69
            $document->__isInitialized__ = true;
0 ignored issues
show
Bug introduced by
Accessing __isInitialized__ on the interface Doctrine\ODM\MongoDB\Proxy\Proxy suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
459 69
            $document->__setInitializer(null);
460 69
            $document->__setCloner(null);
461
            // lazy properties may be left uninitialized
462 69
            $properties = $document->__getLazyProperties();
463 69
            foreach ($properties as $propertyName => $property) {
464 27
                if ( ! isset($document->$propertyName)) {
465 27
                    $document->$propertyName = $properties[$propertyName];
466
                }
467
            }
468
        }
469
470
        // Invoke the postLoad lifecycle callbacks and listeners
471 412 View Code Duplication
        if ( ! empty($metadata->lifecycleCallbacks[Events::postLoad])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
472 13
            $metadata->invokeLifecycleCallbacks(Events::postLoad, $document, array(new LifecycleEventArgs($document, $this->dm)));
473
        }
474 412 View Code Duplication
        if ($this->evm->hasListeners(Events::postLoad)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
475 4
            $this->evm->dispatchEvent(Events::postLoad, new LifecycleEventArgs($document, $this->dm));
476
        }
477
478 412
        return $data;
479
    }
480
}
481