PHPSA\Compiler\Expression\BinaryOp\SpaceShip::compile PHP Method

compile() protected method

It's used in conditions {left-expr} <=> {right-expr}
protected compile ( PhpParser\Node\Expr\BinaryOp\Spaceship $expr, Context $context ) : CompiledExpression
$expr PhpParser\Node\Expr\BinaryOp\Spaceship
$context PHPSA\Context
return PHPSA\CompiledExpression
    protected function compile($expr, Context $context)
    {
        $left = $context->getExpressionCompiler()->compile($expr->left);
        $right = $context->getExpressionCompiler()->compile($expr->right);
        if ($left->isTypeKnown() && $right->isTypeKnown()) {
            if ($left->getValue() == $right->getValue()) {
                return new CompiledExpression(CompiledExpression::INTEGER, 0);
            } elseif ($left->getValue() < $right->getValue()) {
                return new CompiledExpression(CompiledExpression::INTEGER, -1);
            } elseif ($left->getValue() > $right->getValue()) {
                return new CompiledExpression(CompiledExpression::INTEGER, 1);
            }
        }
        return new CompiledExpression();
    }
SpaceShip