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 — 2.2 (#156)
by Simone
07:17 queued 03:31
created

CurrentMetaData   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
dl 0
loc 56
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A justEntitiesMetadata() 0 5 1
A extractFields() 0 7 1
A fromEntityManager() 0 3 1
A haveRelations() 0 3 1
A getRelations() 0 11 2
A __construct() 0 9 1
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