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.

MapBuilder::rebuildRelationMap()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 13
c 0
b 0
f 0
ccs 6
cts 6
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Mado\QueryBundle\Component\Meta;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Doctrine\ORM\Mapping\ClassMetadata;
7
8
/**
9
 * @since Class available since Release 2.1.0
10
 */
11
class MapBuilder implements DataMapper
12
{
13
    private $manager;
14
15
    private $map = [];
16
17 3
    public function __construct(EntityManagerInterface $manager)
18
    {
19 3
        $this->manager = $manager;
20 3
    }
21
22
    public function setMap(array $map) : bool
23
    {
24
        $this->map = $map;
25
26
        return true;
27
    }
28
29 3
    public function getMap() : array
30
    {
31 3
        if ($this->map == []) {
32 2
            $this->rebuildRelationMap();
33
        }
34
35 3
        return $this->map;
36
    }
37
38 1
    public function forceCache(array $map)
39
    {
40 1
        $this->map = $map;
41 1
    }
42
43
    /** @codeCoverageIgnore */
44
    public static function relations(ClassMetadata $classMetadata)
45
    {
46
        $encoded = json_encode($classMetadata);
47
        $decoded = json_decode($encoded, true);
48
        $relations = $decoded['associationMappings'];
49
50
        $relMap = [];
51
52
        foreach ($relations as $name => $meta) {
53
            $relMap[$name] = $meta['targetEntity'];
54
        }
55
56
        return $relMap;
57
    }
58
59 2
    public function rebuildRelationMap() : bool
60
    {
61 2
        $allMetadata = $this->manager
62 2
            ->getMetadataFactory()
63 2
            ->getAllMetadata();
64
65 2
        foreach ($allMetadata as $singleEntityMetadata) {
66
            // @codeCoverageIgnoreStart
67
            $this->map[$singleEntityMetadata->getName()]['relations'] = self::relations($singleEntityMetadata);
68
            // @codeCoverageIgnoreEnd
69
        }
70
71 2
        return true;
72
    }
73
}
74