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:55
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 getMap() 0 5 1
A __construct() 0 3 1
A relations() 0 13 2
A rebuildRelationMap() 0 9 2
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
    /** @codeCoverageIgnore */
27
    public static function relations(ClassMetadata $classMetadata)
28
    {
29
        $encoded = json_encode($classMetadata);
30
        $decoded = json_decode($encoded, true);
31
        $relations = $decoded['associationMappings'];
32
33
        $relMap = [];
34
35
        foreach ($relations as $name => $meta) {
36
            $relMap[$name] = $meta['targetEntity'];
37
        }
38
39
        return $relMap;
40
    }
41
42
    public function rebuildRelationMap()
43
    {
44
        $allMetadata = $this->manager
45
            ->getMetadataFactory()
46
            ->getAllMetadata();
47
48
        foreach ($allMetadata as $singleEntityMetadata) {
49
            // @codeCoverageIgnoreStart
50
            $this->map[$singleEntityMetadata->getName()]['relations'] = self::relations($singleEntityMetadata);
51
            // @codeCoverageIgnoreEnd
52
        }
53
    }
54
}
55