ClassMetadataFactory::getMetadataFor()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 21
Code Lines 12

Duplication

Lines 8
Ratio 38.1 %

Importance

Changes 0
Metric Value
dl 8
loc 21
rs 9.0534
c 0
b 0
f 0
cc 4
eloc 12
nc 5
nop 1
1
<?php
2
3
/**
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Cubiche\Infrastructure\Doctrine\ODM\MongoDB\Mapping;
12
13
use Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory as BaseClassMetadataFactory;
14
use Doctrine\ODM\MongoDB\DocumentManager;
15
use Cubiche\Infrastructure\Doctrine\ODM\MongoDB\Events;
16
use Cubiche\Infrastructure\Doctrine\ODM\MongoDB\Event\PreLoadClassMetadataEventArgs;
17
use Doctrine\ODM\MongoDB\Event\LoadClassMetadataEventArgs;
18
19
/**
20
 * ClassMetadata Factory Class.
21
 *
22
 * @author Karel Osorio Ramírez <[email protected]>
23
 */
24
class ClassMetadataFactory extends BaseClassMetadataFactory
25
{
26
    /**
27
     * @var ClassMetadata[]
28
     */
29
    private $innerLoadedMetadata = [];
30
31
    /**
32
     * @var DocumentManager
33
     */
34
    private $documentManager;
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getMetadataFor($className)
40
    {
41
        if (!isset($this->innerLoadedMetadata[$className])) {
42
            $evm = $this->documentManager->getEventManager();
43 View Code Duplication
            if ($evm->hasListeners(Events::PRE_LOAD_CLASSMETADATA)) {
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...
44
                $eventArgs = new PreLoadClassMetadataEventArgs($className, $this->documentManager);
45
                $evm->dispatchEvent(Events::PRE_LOAD_CLASSMETADATA, $eventArgs);
46
            }
47
48
            $classMetadata = parent::getMetadataFor($className);
49
50 View Code Duplication
            if ($evm->hasListeners(Events::POST_LOAD_CLASS_METADATA)) {
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...
51
                $eventArgs = new LoadClassMetadataEventArgs($classMetadata, $this->documentManager);
52
                $evm->dispatchEvent(Events::POST_LOAD_CLASS_METADATA, $eventArgs);
53
            }
54
55
            $this->innerLoadedMetadata[$className] = $classMetadata;
56
        }
57
58
        return $this->innerLoadedMetadata[$className];
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->innerLoadedMetadata[$className]; of type Cubiche\Infrastructure\D...e\Mapping\ClassMetadata adds the type Cubiche\Infrastructure\D...B\Mapping\ClassMetadata to the return on line 58 which is incompatible with the return type declared by the interface Doctrine\Common\Persiste...Factory::getMetadataFor of type Doctrine\Common\Persistence\Mapping\ClassMetadata.
Loading history...
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function setDocumentManager(DocumentManager $dm)
65
    {
66
        parent::setDocumentManager($dm);
67
        $this->documentManager = $dm;
68
    }
69
}
70