SassScriptOperation::perform PHP Method

perform() public method

Performs this operation.
public perform ( array $operands ) : SassLiteral
$operands array operands for the operation. The operands are SassLiterals
return SassLiteral the result of the operation
    public function perform($operands)
    {
        if (count($operands) !== $this->operandCount) {
            throw new SassScriptOperationException('Incorrect operand count for ' . get_class($operands[0]) . '; expected ' . $this->operandCount . ', received ' . count($operands), SassScriptParser::$context->node);
        }
        if (!count($operands)) {
            return $operands;
        }
        // fix a bug of unknown origin
        foreach ($operands as $i => $op) {
            if (!is_object($op)) {
                $operands[] = null;
                unset($operands[$i]);
            }
        }
        $operands = array_values($operands);
        if (count($operands) > 1 && $operands[1] === null) {
            $operation = 'op_unary_' . $this->operator;
        } else {
            $operation = 'op_' . $this->operator;
            if ($this->associativity == 'l') {
                $operands = array_reverse($operands);
            }
        }
        if (method_exists($operands[0], $operation)) {
            $op = clone $operands[0];
            return $op->{$operation}(!empty($operands[1]) ? $operands[1] : null);
        }
        # avoid failures in case of null operands
        $count = count($operands);
        foreach ($operands as $i => $op) {
            if ($op === null) {
                $count--;
            }
        }
        if ($count) {
            throw new SassScriptOperationException('Undefined operation "' . $operation . '" for ' . get_class($operands[0]), SassScriptParser::$context->node);
        }
    }