final class ExpressionEvaluator
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.

Works out what values an expression can take at the point it is written.

Methods§

public function __construct(
    ReferenceEvaluator $references,
    CallEvaluator $calls,
    EvaluationBudget $budget,
    NodeText $text,
)

Wires the evaluator to the parts that read references and follow calls.

Parameters

public function evaluate(Expr $node, Environment $environment, FunctionScope $scope): Domain

Every value the expression can take.

Parameters

$nodeExpr
$environmentEnvironment
$scopeFunctionScope

Returns

Called from 42
Calls 15
public function evaluateOperands(
    Expr $node,
    Environment $environment,
    FunctionScope $scope,
): void

Evaluates whatever an expression is written over, for what those evaluations find.

A statement can sit anywhere an expression can, including in an operand the analyzer has no use for the value of. $enabled && $pdo->query(…) issues a query whatever $enabled turns out to be, so finding the call must not depend on the analyzer caring about the expression around it. Every call written inside an operand is evaluated even when the value of the expression holding it is discarded.

Parameters

$nodeExpr
$environmentEnvironment
$scopeFunctionScope
Called from 2
Calls 3
public function evaluateScalar(Expr $node): ?Domain

The value of a literal expression, or null when the expression is not one.

Parameters

$nodeExpr

Returns

Called from 1
Calls 1
public function evaluateClone(
    Clone_ $node,
    Environment $environment,
    FunctionScope $scope,
): Domain

Clones a tracked object without sharing its allocation with the original.

Parameters

$nodeClone_
$environmentEnvironment
$scopeFunctionScope

Returns

Called from 1
Calls 4
public function evaluateOptionalRight(
    BinaryOp $node,
    Environment $environment,
    FunctionScope $scope,
): Domain

Keeps the effects of executing and skipping a short-circuited operand.

Parameters

$nodeBinaryOp
$environmentEnvironment
$scopeFunctionScope

Returns

Called from 1
Calls 7
public function evaluateCast(Cast $node, Environment $environment, FunctionScope $scope): Domain

The value of a cast, which narrows to a scalar type and, for the numeric casts, also ends the trail back to whatever the value came from.

Casting to int neutralises a value as a source of injected SQL, so the result deliberately no longer carries the operand's origin.

Parameters

$nodeCast
$environmentEnvironment
$scopeFunctionScope

Returns

Called from 1
Calls 6
public function castLiteral(string|int|float|bool|null $value, string $type): Domain

A resolved scalar written as the type it is cast to.

Parameters

$valuestring|int|float|bool|null
$typestring

Returns

Called from 1
Calls 1
public function evaluateResult(
    Expr $node,
    Environment $environment,
    FunctionScope $scope,
): ?Domain

The value of an expression whose operands matter more than its result.

The operands are evaluated for what those evaluations find, and the result is reported by the type the operator produces.

Parameters

$nodeExpr
$environmentEnvironment
$scopeFunctionScope

Returns

Called from 1
Calls 5
public function resultType(Expr $node): ?string

The type an operator produces, or null when the node is not one.

Parameters

$nodeExpr

Returns

?string
Called from 1
public function evaluateInterpolation(
    InterpolatedString $node,
    Environment $environment,
    FunctionScope $scope,
): Domain

The value of a double-quoted string or heredoc with expressions inside it.

Parameters

$nodeInterpolatedString
$environmentEnvironment
$scopeFunctionScope

Returns

Called from 1
Calls 2
public function evaluateTernary(
    Ternary $node,
    Environment $environment,
    FunctionScope $scope,
): Domain

The value of a conditional, which is whichever branch runs.

Parameters

$nodeTernary
$environmentEnvironment
$scopeFunctionScope

Returns

Called from 1
Calls 3
public function evaluateIsset(
    Isset_ $node,
    Environment $environment,
    FunctionScope $scope,
): Domain

An existence test's boolean result stays open; its operands may have effects.

Parameters

$nodeIsset_
$environmentEnvironment
$scopeFunctionScope

Returns

Called from 1
Calls 7
public function evaluateMatch(
    Match_ $node,
    Environment $environment,
    FunctionScope $scope,
): Domain
public function evaluateAssign(
    Assign $node,
    Environment $environment,
    FunctionScope $scope,
): Domain

The value of an assignment, which is also written into the environment.

Parameters

$nodeAssign
$environmentEnvironment
$scopeFunctionScope

Returns

Called from 1
Calls 2
public function evaluateAppend(
    Concat $node,
    Environment $environment,
    FunctionScope $scope,
): Domain

The value of an appending assignment, which is also written into the environment.

Parameters

$nodeConcat
$environmentEnvironment
$scopeFunctionScope

Returns

Called from 1
Calls 2

Private surface 5§

Implementation details, listed for orientation only.

private ReferenceEvaluator $references
private CallEvaluator $calls
private EvaluationBudget $budget
private NodeText $text
private int $clones = 0

Test cases 24§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 1
Other tests reaching this symbol 23

Relations§

Instantiated in 1
Method calls 27
Type declarations 39