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.

BaseParser::buildFunction()   C
last analyzed

Complexity

Conditions 8
Paths 11

Size

Total Lines 41
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 41
rs 5.3846
c 0
b 0
f 0
cc 8
eloc 34
nc 11
nop 2
1
<?php
2
3
namespace Pinq\Queries\Builders\Interpretations;
4
5
use Pinq\Parsing\IFunctionInterpreter;
6
use Pinq\PinqException;
7
use Pinq\Queries;
8
use Pinq\Queries\Builders\Functions\CallableFunction;
9
use Pinq\Queries\Builders\Functions\ClosureExpressionFunction;
10
use Pinq\Queries\Builders\Functions\IFunction;
11
12
/**
13
 * Base class for query expression parsing.
14
 *
15
 * @author Elliot Levin <[email protected]>
16
 */
17
class BaseParser extends BaseInterpretation implements IQueryParser
18
{
19
    public function __construct(IFunctionInterpreter $functionInterpreter)
20
    {
21
        parent::__construct($functionInterpreter);
22
    }
23
24
    final protected function buildFunction(IFunction $function, callable $factory)
25
    {
26
        if ($function instanceof CallableFunction) {
27
            $reflection           = $this->functionInterpreter->getReflection($function->getCallable());
28
            $scopeType            = $reflection->getScope()->getScopeType();
29
            $namespace            = $reflection->getInnerReflection()->getNamespaceName() ?: null;
30
            $parameterExpressions = $reflection->getSignature()->getParameterExpressions();
31
            $scopedVariableNames  = $reflection->getSignature()->isStatic() ? [] : ['this'];
32
            $scopedVariableNames  = array_merge(
33
                    $scopedVariableNames,
34
                    $reflection->getSignature()->getScopedVariableNames() ?: []
35
            );
36
            $bodyExpressions      = $reflection->getInnerReflection()->isUserDefined()
37
                    ? $this->functionInterpreter->getStructure($reflection)->getBodyExpressions() : null;
38
        } elseif ($function instanceof ClosureExpressionFunction) {
39
            if ($function->hasEvaluationContext()) {
40
                $scopeType = $function->getEvaluationContext()->getScopeType();
41
                $namespace = $function->getEvaluationContext()->getNamespace();
42
            } else {
43
                $scopeType = null;
44
                $namespace = null;
45
            }
46
            $expression           = $function->getExpression();
47
            $parameterExpressions = $expression->getParameters();
48
            $bodyExpressions      = $expression->getBodyExpressions();
49
            $scopedVariableNames  = array_merge(['this'], $expression->getUsedVariableNames());
50
        } else {
51
            throw new PinqException(
52
                    'Cannot build function: unsupported function type, %s',
53
                    get_class($function));
54
        }
55
56
        return $factory(
57
                $this->getFunctionCallableParameter($function),
58
                $scopeType,
59
                $namespace,
60
                $this->getFunctionScopeParameterMap($function, $scopedVariableNames),
61
                $parameterExpressions,
62
                $bodyExpressions
63
        );
64
    }
65
66
    final protected function getFunctionScopeParameterMap(IFunction $function, array $scopedVariableNames)
67
    {
68
        $parameterScopedVariableMap = [];
69
70
        foreach (array_unique($scopedVariableNames) as $scopedVariable) {
71
            $parameterScopedVariableMap[$this->getFunctionScopedVariableParameter(
72
                    $function,
73
                    $scopedVariable
74
            )] = $scopedVariable;
75
        }
76
77
        return $parameterScopedVariableMap;
78
    }
79
}
80