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:46 queued 03:48
created

CurrentMetaData   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
dl 0
loc 85
ccs 40
cts 40
cp 1
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A justEntitiesMetadata() 0 5 1
A fromEntityManager() 0 3 1
A __construct() 0 9 1
A hasRelations() 0 3 1
A extraction() 0 7 1
A extractFieldsType() 0 6 1
A getCurrentAssociationMapping() 0 3 1
A extractFields() 0 6 1
A getRelations() 0 15 3
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 7
    private function __construct(EntityManagerInterface $manager)
18
    {
19 7
        $this->manager = $manager;
20
21 7
        $metadata = $this->manager
22 7
            ->getMetaDataFactory()
23 7
            ->getAllMetaData();
24
25 7
        $this->metadata = $metadata;
26 7
    }
27
28 7
    public static function fromEntityManager(EntityManagerInterface $manager) : CurrentMetaData
29
    {
30 7
        return new self($manager);
31
    }
32
33
    public function justEntitiesMetadata() : array
34
    {
35 7
        return array_map(function ($item) {
36 7
            return $item->rootEntityName;
37 7
        }, $this->metadata);
38
    }
39
40 3
    public function extractFields($entityClass) : array
41
    {
42 3
        return $this->extraction(
43
            $entityClass,
44 3
            function ($item) {
45 3
                return Dictionary::getOperatorsFromDoctrineType($item);
46 3
            }
47
        );
48
    }
49
50 4
    public function extractFieldsType($entityClass) : array
51
    {
52 4
        return $this->extraction(
53
            $entityClass,
54 4
            function ($item) {
55 4
                return $item;
56 4
            }
57
        );
58
    }
59
60 7
    private function extraction($entityClass, callable $step) : array
61
    {
62 7
        $this->currentMetadata = $this->manager->getClassMetadata($entityClass);
63
64 7
        return array_map(function ($item) use ($step) {
65 7
            return $step($item['type']);
66 7
        }, $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...
67
    }
68
69 6
    public function hasRelations() : bool
70
    {
71 6
        return count($this->getCurrentAssociationMapping()) > 0;
72
    }
73
74 6
    public function getCurrentAssociationMapping()
75
    {
76 6
        return $this->currentMetadata->associationMappings;
77
    }
78
79 6
    public function getRelations() : array
80
    {
81 6
        $relations = [];
82
83 6
        foreach ($this->getCurrentAssociationMapping() as $rel) {
84 6
            $relationName = $rel['inversedBy'] == ''
85 6
                ? $rel['mappedBy']
86 6
                : $rel['inversedBy'];
87
88 6
            $relations[$relationName] = StringParser::dotNotationFor(
89 6
                $rel['targetEntity']
90
            );
91
        }
92
93 6
        return $relations;
94
    }
95
}
96