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

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
c 0
b 0
f 0
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 1
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) {
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