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
Push — 2.3 ( 8686ea...f49551 )
by Simone
04:54
created

MapBuilder   A

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) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->map of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
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