Asserts that the literal is the expected type
public static assertType ( $literal, string $type ) | ||
$type | string | expected type |
/** * Inspects the type of the argument, returning it as an unquoted string. * @param SassLiteral The object to inspect * @return new SassString The type of object * @throws SassScriptFunctionException If $obj is not an instance of a * SassLiteral */ public static function type_of($obj) { SassLiteral::assertType($obj, SassLiteral); return new SassString($obj->typeOf); }
public static function grad_position($colourList, $index, $default, $radial = null) { SassLiteral::assertType($colourList, 'CompassList'); if (is_null($radial)) { $radial = new SassBoolean(false); } else { SassLiteral::assertType($radial, 'SassBoolean'); } $stop = $colourList->values[$index->value - 1]->stop; if ($stop && $radial->value) { $orig_stop = $stop; if ($stop->isUnitless()) { if ($stop->value <= 1) { # A unitless number is assumed to be a percentage when it's between 0 and 1 $stop = $stop->op_times(new SassNumber('100%')); } else { # Otherwise, a unitless number is assumed to be in pixels $stop = $stop->op_times(new SassNumber('1px')); } } if ($stop->numeratorUnits === '%' && isset($colourList->values[sizeof($colourList->values) - 1]->stop) && $colourList->values[sizeof($colourList->values) - 1]->stop->numeratorUnits === 'px') { $stop = $stop->op_times($colourList->values[sizeof($colourList->values) - 1]->stop)->op_div(new SassNumber('100%')); } //Compass::Logger.new.record(:warning, "Webkit only supports pixels for the start and end stops for radial gradients. Got: #{orig_stop}") if stop.numerator_units != ["px"]; return $stop->op_div(new SassNumber('1' . $stop->units)); } elseif ($stop) { return $stop; } else { return $default; } }