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
02:35
created

MapBuilder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 41
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 8 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
class MapBuilder implements RelationDatamapper
9
{
10
    private $manager;
11
12
    private $map = [];
13
14
    public function __construct(EntityManager $manager)
15
    {
16
        $this->manager = $manager;
17
    }
18
19
    public function getMap() : array
20
    {
21
        $this->rebuildRelationMap();
22
23
        return $this->map;
24
    }
25
26
    public static function relations(ClassMetadata $classMetadata)
27
    {
28
        $encoded = json_encode($classMetadata);
29
        $decoded = json_decode($encoded, true);
30
        $relations = $decoded['associationMappings'];
31
32
        $relMap = [];
33
34
        foreach ($relations as $name => $meta) {
35
            $relMap[$name] = $meta['targetEntity'];
36
        }
37
38
        return $relMap;
39
    }
40
41
    public function rebuildRelationMap()
42
    {
43
        $allMetadata = $this->manager
44
            ->getMetadataFactory()
45
            ->getAllMetadata();
46
47
        foreach ($allMetadata as $singleEntityMetadata) {
48
            $this->map[$singleEntityMetadata->getName()]['relations'] = self::relations($singleEntityMetadata);
49
        }
50
    }
51
}
52