You are here

public function SassScriptOperation::perform in Sassy 7

Same name and namespace in other branches
  1. 7.3 phpsass/script/SassScriptOperation.php \SassScriptOperation::perform()

* Performs this operation. *

Parameters

array operands for the operation. The operands are SassLiterals: * @return SassLiteral the result of the operation * @throws SassScriptOperationException if the oprand count is incorrect or * the operation is undefined

File

phamlp/sass/script/SassScriptOperation.php, line 120

Class

SassScriptOperation
SassScriptOperation class. The operation to perform. @package PHamlP @subpackage Sass.script

Code

public function perform($operands) {
  if (count($operands) !== $this->operandCount) {
    throw new SassScriptOperationException('Incorrect operand count for {operation}; expected {expected}, received {received}', array(
      '{operation}' => get_class($operands[0]),
      '{expected}' => $this->operandCount,
      '{received}' => count($operands),
    ), SassScriptParser::$context->node);
  }
  if (count($operands) > 1 && is_null($operands[1])) {
    $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);
  }
  throw new SassScriptOperationException('Undefined operation "{operation}" for {what}', array(
    '{operation}' => $operation,
    '{what}' => get_class($operands[0]),
  ), SassScriptParser::$context->node);
}