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/2.2/provide_field_usab... ( 03364e...b3bc72 )
by Simone
03:35
created

CurrentMetaData::getRelations()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Mado\QueryBundle\Component\Sherlock;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Mado\QueryBundle\Dictionary;
7
use Mado\QueryBundle\Services\StringParser;
8
9
class CurrentMetaData
10
{
11
    private $metadata;
12
13
    private $manager;
14
15
    private $currentMetadata;
16
17 2
    private function __construct(EntityManagerInterface $manager)
18
    {
19 2
        $this->manager = $manager;
20
21 2
        $metadata = $this->manager
22 2
            ->getMetaDataFactory()
23 2
            ->getAllMetaData();
24
25 2
        $this->metadata = $metadata;
26 2
    }
27
28 2
    public static function fromEntityManager(EntityManagerInterface $manager) : CurrentMetaData
29
    {
30 2
        return new self($manager);
31
    }
32
33
    public function justEntitiesMetadata() : array
34
    {
35 2
        return array_map(function ($item) {
36 2
            return $item->rootEntityName;
37 2
        }, $this->metadata);
38
    }
39
40 2
    public function extractFields($entityClass) : array
41
    {
42 2
        $this->currentMetadata = $this->manager->getClassMetadata($entityClass);
43
44 2
        return array_map(function ($item) {
45 2
            return Dictionary::getOperatorsFromDoctrineType($item['type']);
46 2
        }, $this->currentMetadata->fieldMappings);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
47
    }
48
49 2
    public function haveRelations() : bool
50
    {
51 2
        return count($this->currentMetadata->associationMappings) > 0;
52
    }
53
54 2
    public function getRelations() : array
55
    {
56 2
        $relations = [];
57
58 2
        foreach ($this->currentMetadata->associationMappings as $rel) {
59
            $relations[
60 2
                $rel['inversedBy']
61 2
            ] = StringParser::dotNotationFor($rel['targetEntity']);
62
        }
63
64 2
        return $relations;
65
    }
66
}
67