GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#62)
by Simone
03:02
created

MapBuilder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A relations() 0 13 2
A getMap() 0 5 1
A rebuildRelationMap() 0 9 2
A __construct() 0 3 1
1
<?php
2
3
namespace Mado\QueryBundle\Component\Meta;
4
5
use Doctrine\ORM\EntityManager;
6
use Doctrine\ORM\Mapping\ClassMetadata;
7
8
/**
9
 * @since Class available since Release 2.1.0
10
 */
11
class MapBuilder implements RelationDataMapper
12
{
13
    private $manager;
14
15
    private $map = [];
16
17
    public function __construct(EntityManager $manager)
18
    {
19
        $this->manager = $manager;
20
    }
21
22
    public function getMap() : array
23
    {
24
        $this->rebuildRelationMap();
25
26
        return $this->map;
27
    }
28
29
    /** @codeCoverageIgnore */
30
    public static function relations(ClassMetadata $classMetadata)
31
    {
32
        $encoded = json_encode($classMetadata);
33
        $decoded = json_decode($encoded, true);
34
        $relations = $decoded['associationMappings'];
35
36
        $relMap = [];
37
38
        foreach ($relations as $name => $meta) {
39
            $relMap[$name] = $meta['targetEntity'];
40
        }
41
42
        return $relMap;
43
    }
44
45
    public function rebuildRelationMap()
46
    {
47
        $allMetadata = $this->manager
48
            ->getMetadataFactory()
49
            ->getAllMetadata();
50
51
        foreach ($allMetadata as $singleEntityMetadata) {
52
            // @codeCoverageIgnoreStart
53
            $this->map[$singleEntityMetadata->getName()]['relations'] = self::relations($singleEntityMetadata);
54
            // @codeCoverageIgnoreEnd
55
        }
56
    }
57
}
58