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.

FunctionScope::getThisType()   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\Parsing;
4
5
use Pinq\Expressions as O;
6
7
/**
8
 * Implementation of the function scope interface.
9
 *
10
 * @author Elliot Levin <[email protected]>
11
 */
12
class FunctionScope implements IFunctionScope
13
{
14
    /**
15
     * @var object|null
16
     */
17
    protected $thisObject;
18
19
    /**
20
     * @var string|null
21
     */
22
    protected $thisType;
23
24
    /**
25
     * @var string|null
26
     */
27
    protected $scopeType;
28
29
    /**
30
     * @var array<string, mixed>
31
     */
32
    protected $variableValueMap;
33
34
    public function __construct(
35
            $thisObject,
36
            $scopeType,
37
            array $variableValueMap
38
    ) {
39
        $this->thisObject = $thisObject;
40
        $this->thisType = $thisObject !== null ? get_class($thisObject) : null;
41
        $this->scopeType = $scopeType;
42
        $this->variableValueMap = $variableValueMap;
43
    }
44
45
    /**
46
     * Creates a function scope instance from the supplied reflection and callable.
47
     *
48
     * @param \ReflectionFunctionAbstract $reflection
49
     * @param callable                    $callable
50
     *
51
     * @return self
52
     */
53
    public static function fromReflection(\ReflectionFunctionAbstract $reflection, callable $callable)
54
    {
55
        if (is_array($callable)) {
56
            /** @var $reflection \ReflectionMethod */
57
            $thisObject = is_object($callable[0]) ? $callable[0] : null;
58
            $scopeType = $reflection->getDeclaringClass()->getName();
0 ignored issues
show
introduced by
Consider using $reflection->class. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
59
        } elseif (is_object($callable) && !($callable instanceof \Closure)) {
60
            /** @var $reflection \ReflectionMethod */
61
            $thisObject = $callable;
62
            $scopeType = $reflection->getDeclaringClass()->getName();
0 ignored issues
show
introduced by
Consider using $reflection->class. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
63
        } elseif ($reflection->isClosure()) {
64
            $thisObject = $reflection->getClosureThis();
65
            $scopeClass = $reflection->getClosureScopeClass();
66
            $scopeType = $scopeClass === null ? null : $scopeClass->getName();
67
        } else {
68
            $thisObject = null;
69
            $scopeType = null;
70
        }
71
        $variableTable = $reflection->getStaticVariables();
72
73
        return new self($thisObject, $scopeType, $variableTable);
74
    }
75
76
    public function hasThis()
77
    {
78
        return $this->thisObject !== null;
79
    }
80
81
    public function getThis()
82
    {
83
        return $this->thisObject;
84
    }
85
86
    public function getThisType()
87
    {
88
        return $this->thisType;
89
    }
90
91
    public function getScopeType()
92
    {
93
        return $this->scopeType;
94
    }
95
96
    public function getVariableTable()
97
    {
98
        return $this->variableValueMap;
99
    }
100
101
    public function asEvaluationContext(array $variableTable = [], $namespace = null)
102
    {
103
        return new O\EvaluationContext(
104
                $namespace,
105
                $this->scopeType,
106
                $this->thisObject,
107
                //Used variables take precedence over arguments: http://3v4l.org/V4LSE
108
                $this->variableValueMap + $variableTable
109
        );
110
    }
111
}
112