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.

QueryProvider   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 71
Duplicated Lines 21.13 %

Coupling/Cohesion

Components 2
Dependencies 10

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 10
dl 15
loc 71
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A getQueryResultCollection() 0 4 1
A loadRequestExpression() 15 15 2
loadRequest() 0 4 ?
A createQueryable() 0 4 1
A load() 0 16 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Pinq\Providers;
4
5
use Pinq\Expressions as O;
6
use Pinq\Queries;
7
use Pinq\Queries\Builders;
8
use Pinq\Queryable;
9
10
/**
11
 * Base class for the query provider.
12
 *
13
 * @author Elliot Levin <[email protected]>
14
 */
15
abstract class QueryProvider extends ProviderBase implements IQueryProvider
16
{
17
    /**
18
     * @var Builders\IRequestQueryBuilder
19
     */
20
    protected $requestBuilder;
21
22
    public function __construct(
23
            Queries\ISourceInfo $sourceInfo,
24
            Configuration\IQueryConfiguration $configuration = null
25
    ) {
26
        parent::__construct($sourceInfo, $configuration ?: new Configuration\DefaultQueryConfiguration());
27
28
        $this->requestBuilder        = $this->configuration->getRequestQueryBuilder();
29
        $this->queryResultCollection = $this->configuration->getQueryResultCollection();
30
    }
31
32
    public function getQueryResultCollection()
33
    {
34
        return $this->queryResultCollection;
35
    }
36
37
    public function createQueryable(O\TraversalExpression $scopeExpression = null)
38
    {
39
        return new Queryable($this, $this->sourceInfo, $scopeExpression, $this->scheme);
40
    }
41
42
    public function load(O\Expression $requestExpression)
43
    {
44
        if ($this->queryResultCollection === null) {
45
            return $this->loadRequestExpression($requestExpression);
46
        }
47
48
        if ($this->queryResultCollection->tryComputeResults($requestExpression, $results)) {
49
            return $results;
50
        }
51
52
        $queryExpression = $this->queryResultCollection->optimizeQuery($requestExpression);
53
        $results = $this->loadRequestExpression($queryExpression);
54
        $this->queryResultCollection->saveResults($queryExpression, $results);
55
56
        return $this->queryResultCollection->computeResults($requestExpression);
57
    }
58
59 View Code Duplication
    protected function loadRequestExpression(O\Expression $requestExpression)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
    {
61
        $resolution = $this->requestBuilder->resolveRequest($requestExpression);
62
        $queryHash  = $resolution->getHash();
63
        $query      = $this->queryCache->tryGet($queryHash);
64
65
        if (!($query instanceof Queries\IRequestQuery)) {
66
            $query = $this->requestBuilder->parseRequest($requestExpression);
67
            $this->queryCache->save($queryHash, $query);
68
        }
69
70
        $resolvedParameters = $query->getParameters()->resolve($resolution);
71
72
        return $this->loadRequest($query, $resolvedParameters);
73
    }
74
75
    /**
76
     * @param Queries\IRequestQuery              $request
77
     * @param Queries\IResolvedParameterRegistry $resolvedParameters
78
     *
79
     * @return mixed
80
     */
81
    abstract protected function loadRequest(
82
            Queries\IRequestQuery $request,
83
            Queries\IResolvedParameterRegistry $resolvedParameters
84
    );
85
}
86