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   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 84.21%

Importance

Changes 0
Metric Value
wmc 9
eloc 23
dl 0
loc 61
c 0
b 0
f 0
ccs 16
cts 19
cp 0.8421
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A forceCache() 0 3 1
A __construct() 0 3 1
A setMap() 0 5 1
A relations() 0 13 2
A getMap() 0 7 2
A rebuildRelationMap() 0 13 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