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

Sherlock::getOpList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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 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 3
                    $flip[$rel] = $fields;
59
                }
60 3
                $opList[$entity]['_embedded'] = $flip;
61
            }
62
63 6
            if ($this->metadata->hasRelations()) {
64 6
                $relations = $this->metadata->getRelations();
65 6
                $opList[$entity]['relations'][] = $relations;
66
            }
67
        }
68
69 6
        return $opList;
70
    }
71
72 2
    public function getRelations($entityPath) : array
73
    {
74 2
        return current($this->getOpList($entityPath)['relations']);
75
    }
76
77 4
    public function getFieldsType($entityPath) : array
78
    {
79 4
        $fieldTypes = [];
80
81 4
        foreach ($this->metadata->justEntitiesMetadata() as $entityClass) {
82 4
            $fields = $this->metadata->extractFieldsType($entityClass);
83
84 4
            $entity = StringParser::dotNotationFor($entityClass);
85 4
            $fieldTypes[$entity]['fields'] = $fields;
86
        }
87
88 4
        return $fieldTypes[$entityPath];
89
    }
90
91 1
    public function willCall(string $fullyQualifiedClassName) : array
92
    {
93 1
        return $this->getRelations($fullyQualifiedClassName);
94
    }
95
96 3
    public function getSearchable($entityPath) : array
97
    {
98 3
        $raw = $this->getShortOpList($entityPath);
99
100 3
        $ultimateListOfSearchableFields = $raw['fields'];
101
102 3
        foreach ($raw['_embedded'] as $em => $bedded) {
103 3
            foreach ($raw['_embedded'][$em] as $foo => $bar) {
104 3
                $ultimateListOfSearchableFields[$em .'.'. $foo] = $bar;
105
            }
106
        }
107
108 3
        return $ultimateListOfSearchableFields;
109
    }
110
}
111