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.

SourceInterpreter::getInterpretation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Pinq\Queries\Builders;
4
5
use Pinq\Expressions as O;
6
use Pinq\IQueryable;
7
use Pinq\Queries\Builders\Interpretations\ISourceInterpretation;
8
use Pinq\Queries;
9
10
/**
11
 * Implementation of the source expression interpreter.
12
 *
13
 * @author Elliot Levin <[email protected]>
14
 */
15
class SourceInterpreter extends ExpressionInterpreter implements ISourceInterpreter
16
{
17
    /**
18
     * @var string
19
     */
20
    protected $segmentId;
21
22
    /**
23
     * @var ISourceInterpretation
24
     */
25
    protected $interpretation;
26
27
    /**
28
     * @var IScopeInterpreter
29
     */
30
    protected $scopeInterpreter;
31
32
    public function __construct(
33
            $segmentId,
34
            ISourceInterpretation $interpretation,
35
            IScopeInterpreter $scopeInterpreter,
36
            O\IEvaluationContext $evaluationContext = null
37
    ) {
38
        parent::__construct($segmentId, $evaluationContext);
39
        $this->interpretation   = $interpretation;
40
        $this->scopeInterpreter = $scopeInterpreter;
41
    }
42
43
    public function getInterpretation()
44
    {
45
        return $this->interpretation;
46
    }
47
48
    public function interpretSource(O\Expression $expression)
49
    {
50
        $isQueryScope = false;
51
        $queryableQueryResolver = new O\DynamicExpressionWalker([
52
                O\TraversalExpression::getType() =>
53
                        function (O\TraversalExpression $expression, O\ExpressionWalker $self) use (&$isQueryScope) {
54
                            $expression = $expression->updateValue($self->walk($expression->getValue()));
55
56
                            if ($isQueryScope) {
57
                                return $expression;
58
                            } else {
59
                                return $self->walk(O\Expression::value($expression->evaluate($this->evaluationContext)));
60
                            }
61
                        },
62
                O\ValueExpression::getType() =>
63
                        function (O\ValueExpression $expression) use (&$isQueryScope) {
64
                            if ($expression->getValue() instanceof IQueryable) {
65
                                $isQueryScope = true;
66
                            }
67
68
                            return $expression;
69
                        }
70
        ]);
71
72
        $expression = $queryableQueryResolver->walk($expression);
73
74
        if ($isQueryScope) {
75
            $this->scopeInterpreter->interpretScope($expression);
0 ignored issues
show
Bug introduced by
It seems like $expression defined by $queryableQueryResolver->walk($expression) on line 72 can be null; however, Pinq\Queries\Builders\IS...reter::interpretScope() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
76
            $this->interpretation->interpretQueryScope($this->getId('source-scope'), $this->scopeInterpreter->getInterpretation());
77
        } else {
78
            $this->interpretation->interpretArrayOrIterator($this->getId('source-iterator'), $expression->evaluate($this->evaluationContext));
79
        }
80
    }
81
}
82