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
08:11 queued 03:44
created

Sherlock::getAll()   B

Complexity

Conditions 7
Paths 11

Size

Total Lines 41

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 7.025

Importance

Changes 0
Metric Value
dl 0
loc 41
rs 8.3306
c 0
b 0
f 0
ccs 23
cts 25
cp 0.92
cc 7
nc 11
nop 1
crap 7.025
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 Sherlock
10
{
11
    private $currentMetadata;
0 ignored issues
show
introduced by
The private property $currentMetadata is not used, and could be removed.
Loading history...
12
13
    private $manager;
14
15 7
    public function __construct(
16
        EntityManagerInterface $manager
17
    ) {
18 7
        $this->manager = $manager;
19 7
        $this->metadata = CurrentMetaData::fromEntityManager($this->manager);
0 ignored issues
show
Bug Best Practice introduced by
The property metadata does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
20 7
    }
21
22 3
    public function getShortOpList($entityPath) : array
23
    {
24 3
        return $this->getAll([
25 3
            'show_just_type' => true,
26
            'show_embedded' => true,
27 3
        ])[$entityPath];
28
    }
29
30
31 3
    public function getOpList($entityPath) : array
32
    {
33 3
        return $this->getAll()[$entityPath];
34
    }
35
36 6
    public function getAll(array $options = []) : array
37
    {
38 6
        $opList = [];
39
40 6
        foreach ($this->metadata->justEntitiesMetadata() as $entityClass) {
41 6
            if (isset($options['show_just_type'])) {
42 3
                $fields = $this->metadata->extractFieldsType($entityClass);
43
            } else {
44 3
                $fields = $this->metadata->extractFields($entityClass);
45
            }
46
47 6
            $entity = StringParser::dotNotationFor($entityClass);
48 6
            $opList[$entity]['fields'] = $fields;
49
50 6
            if (isset($options['show_embedded'])) {
51 3
                $relations = $this->metadata->getRelations();
52 3
                $keys = array_keys($relations);
53 3
                $flip = array_flip($keys);
54 3
                foreach ($flip as $rel => $item) {
55 3
                    $relationPath = $relations[$rel];
56 3
                    $newSherlock = new Sherlock($this->manager);
57 3
                    $fields = $newSherlock->getFieldsType($relationPath)['fields'];
58
59 3
                    if (!isset($flip[$rel])) {
60
                        throw new \RuntimeException(
61
                            'Oops! Invalid relation name exception'
62
                        );
63
                    }
64
65 3
                    $flip[$rel] = $fields;
66
                }
67 3
                $opList[$entity]['_embedded'] = $flip;
68
            }
69
70 6
            if ($this->metadata->hasRelations()) {
71 6
                $relations = $this->metadata->getRelations();
72 6
                $opList[$entity]['relations'][] = $relations;
73
            }
74
        }
75
76 6
        return $opList;
77
    }
78
79 2
    public function getRelations($entityPath) : array
80
    {
81 2
        return current($this->getOpList($entityPath)['relations']);
82
    }
83
84 4
    public function getFieldsType($entityPath) : array
85
    {
86 4
        $fieldTypes = [];
87
88 4
        foreach ($this->metadata->justEntitiesMetadata() as $entityClass) {
89 4
            $fields = $this->metadata->extractFieldsType($entityClass);
90
91 4
            $entity = StringParser::dotNotationFor($entityClass);
92 4
            $fieldTypes[$entity]['fields'] = $fields;
93
        }
94
95 4
        return $fieldTypes[$entityPath];
96
    }
97
98 1
    public function willCall(string $fullyQualifiedClassName) : array
99
    {
100 1
        return $this->getRelations($fullyQualifiedClassName);
101
    }
102
103 3
    public function getSearchable($entityPath) : array
104
    {
105 3
        $raw = $this->getShortOpList($entityPath);
106
107 3
        $ultimateListOfSearchableFields = $raw['fields'];
108
109 3
        foreach ($raw['_embedded'] as $em => $bedded) {
110 3
            foreach ($raw['_embedded'][$em] as $foo => $bar) {
111 3
                $ultimateListOfSearchableFields[$em .'.'. $foo] = $bar;
112
            }
113
        }
114
115 3
        return $ultimateListOfSearchableFields;
116
    }
117
}
118