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 — feature/removed_unused_code ( 64ce89 )
by Alessandro
04:22
created

MapBuilder::rebuildRelationMap()   A

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
dl 0
loc 13
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
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
use Psr\Log\LoggerInterface;
8
9
/**
10
 * @since Class available since Release 2.1.0
11
 */
12
class MapBuilder implements DataMapper
13
{
14
    private $manager;
15
16
    private $map = [];
17
18 3
    public function __construct(
19
        EntityManagerInterface $manager,
20
        LoggerInterface $logger = null
0 ignored issues
show
Unused Code introduced by
The parameter $logger is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

20
        /** @scrutinizer ignore-unused */ LoggerInterface $logger = null

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
21
    ) {
22 3
        $this->manager = $manager;
23 3
    }
24
25
    public function setMap(array $map) : bool
26
    {
27
        $this->map = $map;
28
29
        return true;
30
    }
31
32 3
    public function getMap() : array
33
    {
34 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...
35 2
            $this->rebuildRelationMap();
36
        }
37
38 3
        return $this->map;
39
    }
40
41 1
    public function forceCache(array $map)
42
    {
43 1
        $this->map = $map;
44 1
    }
45
46
    /** @codeCoverageIgnore */
47
    public static function relations(ClassMetadata $classMetadata) {
48
        $encoded = json_encode($classMetadata);
49
        $decoded = json_decode($encoded, true);
50
        $relations = $decoded['associationMappings'];
51
52
        $relMap = [];
53
54
        foreach ($relations as $name => $meta) {
55
            $relMap[$name] = $meta['targetEntity'];
56
        }
57
58
        return $relMap;
59
    }
60
61 2
    public function rebuildRelationMap() : bool
62
    {
63 2
        $allMetadata = $this->manager
64 2
            ->getMetadataFactory()
65 2
            ->getAllMetadata();
66
67 2
        foreach ($allMetadata as $singleEntityMetadata) {
68
            // @codeCoverageIgnoreStart
69
            $this->map[$singleEntityMetadata->getName()]['relations'] = self::relations($singleEntityMetadata);
70
            // @codeCoverageIgnoreEnd
71
        }
72
73 2
        return true;
74
    }
75
}
76