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.
Completed
Push — master ( f769c2...a53f28 )
by Anderson
05:19
created

QueryParser::ArithmeticPrimary()   C

Complexity

Conditions 12
Paths 12

Size

Total Lines 51
Code Lines 29

Duplication

Lines 9
Ratio 17.65 %

Importance

Changes 0
Metric Value
dl 9
loc 51
rs 5.6668
c 0
b 0
f 0
cc 12
eloc 29
nc 12
nop 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace DoctrineElastic\Query;
4
5
use Doctrine\ORM\Query;
6
use Doctrine\ORM\Query\Parser;
7
use DoctrineElastic\DoctrineMock\GetConfigurationEntityManager;
8
use DoctrineElastic\Elastic\ElasticQuery;
9
10
/**
11
 * Elastic Query parser
12
 * Prepares query for execution
13
 *
14
 * @author Andsalves <[email protected]>
15
 */
16
class QueryParser {
17
18
    /** @var ElasticQuery */
19
    protected $query;
20
21
    /** @var Query\AST\SelectStatement */
22
    private $_ast;
23
24
    /** @var Parser */
25
    private $doctrineParser;
26
27
    public function __construct(ElasticQuery $query) {
28
        $this->query = $query;
29
30
        $doctrineQuery = new Query(new GetConfigurationEntityManager($query->getEntityManager()));
31
        $doctrineQuery->setDQL($query->getDQL());
32
        $this->doctrineParser = new Parser($doctrineQuery);
33
    }
34
35
    public function getAST() {
36
        if (is_null($this->_ast)) {
37
            $this->_ast = $this->doctrineParser->QueryLanguage();
38
        }
39
40
        return $this->_ast;
41
    }
42
43
    /**
44
     * Converts ElasticQuery to SearchParams
45
     *
46
     * @return \DoctrineElastic\Elastic\SearchParams
47
     */
48
    public function parseElasticQuery() {
49
        $outputWalker = new ElasticWalker($this->query, $this->getAST(), $this->getRootClass());
50
51
        return $outputWalker->walkSelectStatement();
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getRootClass() {
58
        /** @var \Doctrine\ORM\Query\AST\IdentificationVariableDeclaration[] $identificationVariableDeclarations */
59
        $identificationVariableDeclarations = $this->getAST()->fromClause->identificationVariableDeclarations;
60
61
        foreach ($identificationVariableDeclarations as $idVarDeclaration) {
62
            if ($idVarDeclaration->rangeVariableDeclaration->isRoot) {
63
                return $idVarDeclaration->rangeVariableDeclaration->abstractSchemaName;
64
            }
65
        }
66
67
        return reset($identificationVariableDeclarations)->rangeVariableDeclaration->abstractSchemaName;
68
    }
69
}
70