Tests\PHPSA\TestCase::newScalarExpr PHP Méthode

newScalarExpr() public méthode

public newScalarExpr ( $value ) : PhpParser\Node\Scalar | PhpParser\Node\Expr\Array_
$value
Résultat PhpParser\Node\Scalar | PhpParser\Node\Expr\Array_
    public function newScalarExpr($value)
    {
        switch (gettype($value)) {
            case 'integer':
                return new Node\Scalar\LNumber($value);
            case 'double':
                return new Node\Scalar\DNumber($value);
            case 'string':
                return new Node\Scalar\String_($value);
            case 'boolean':
                return new Boolean($value);
            case 'NULL':
                return new Nil();
            case 'array':
                if ($value === array()) {
                    return new Node\Expr\Array_(array());
                }
                throw new RuntimeException('newScalarExpr is not working with non-empty arrays');
        }
        throw new RuntimeException('Unexpected type: ' . gettype($value));
    }

Usage Example

Exemple #1
0
 public function testCoalesceVarNotExisting()
 {
     $context = $this->getContext();
     $variable = new VariableNode(new Name("name"));
     $else = parent::newScalarExpr("else");
     $baseExpression = new Node\Expr\BinaryOp\Coalesce($variable, $else);
     $compiledExpression = $this->compileExpression($baseExpression, $context);
     parent::assertInstanceOfCompiledExpression($compiledExpression);
     parent::assertSame(CompiledExpression::STRING, $compiledExpression->getType());
     parent::assertSame("else", $compiledExpression->getValue());
 }