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::relations()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
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