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
Pull Request — master (#62)
by Simone
02:22
created

MapBuilder::rebuildRelationMap()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 16
rs 9.4285
1
<?php
2
3
namespace Mado\QueryBundle\Component\Meta;
4
5
use Doctrine\ORM\EntityManager;
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
    private $logger;
19
20
    public function __construct(
21
        EntityManager $manager,
22
        LoggerInterface $logger = null
23
    ) {
24
        $this->manager = $manager;
25
        $this->logger = $logger;
26
    }
27
28
    public function setMap(array $map) : bool
29
    {
30
        $this->map = $map;
31
32
        return true;
33
    }
34
35
    public function getMap() : array
36
    {
37
        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...
38
            $this->rebuildRelationMap();
39
        }
40
41
        return $this->map;
42
    }
43
44
    public function forceCache(array $map)
45
    {
46
        $this->map = $map;
47
    }
48
49
    /** @codeCoverageIgnore */
50
    public static function relations(
51
        ClassMetadata $classMetadata,
52
        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

52
        /** @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...
53
    ) {
54
        $encoded = json_encode($classMetadata);
55
        $decoded = json_decode($encoded, true);
56
        $relations = $decoded['associationMappings'];
57
58
        $relMap = [];
59
60
        foreach ($relations as $name => $meta) {
61
            $relMap[$name] = $meta['targetEntity'];
62
        }
63
64
        return $relMap;
65
    }
66
67
    public function rebuildRelationMap() : bool
68
    {
69
        $allMetadata = $this->manager
70
            ->getMetadataFactory()
71
            ->getAllMetadata();
72
73
        foreach ($allMetadata as $singleEntityMetadata) {
74
            // @codeCoverageIgnoreStart
75
            $this->map[$singleEntityMetadata->getName()]['relations'] = self::relations(
76
                $singleEntityMetadata,
77
                $this->logger
78
            );
79
            // @codeCoverageIgnoreEnd
80
        }
81
82
        return true;
83
    }
84
}
85