Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
ScssPhp\ScssPhp\Node\Number Class Reference

Dimension + optional units. More...

Inheritance diagram for ScssPhp\ScssPhp\Node\Number:
ScssPhp\ScssPhp\Node

Public Member Functions

 __construct ($dimension, $numeratorUnits, array $denominatorUnits=[])
 Initialize number.
 
 __toString ()
 {}
 
 assertNoUnits ($varName=null)
 
 assertSameUnitOrUnitless (Number $other)
 
 assertUnit ($unit, $varName=null)
 
 coerce (array $newNumeratorUnits, array $newDenominatorUnits)
 Returns a copy of this number, converted to the units represented by $newNumeratorUnits and $newDenominatorUnits.
 
 dividedBy (Number $other)
 
 equals (Number $other)
 
 getDenominatorUnits ()
 
 getDimension ()
 
 getNumeratorUnits ()
 
 greaterThan (Number $other)
 
 greaterThanOrEqual (Number $other)
 
 hasUnit ($unit)
 Checks whether the number has exactly this unit.
 
 hasUnits ()
 Returns true if the number has any units.
 
 isComparableTo (Number $other)
 
 jsonSerialize ()
 
 lessThan (Number $other)
 
 lessThanOrEqual (Number $other)
 
 minus (Number $other)
 
 modulo (Number $other)
 
 offsetExists ($offset)
 
 offsetGet ($offset)
 
 offsetSet ($offset, $value)
 
 offsetUnset ($offset)
 
 output (Compiler $compiler=null)
 Output number.
 
 plus (Number $other)
 
 times (Number $other)
 
 unaryMinus ()
 
 unitless ()
 Returns true if the number is unitless.
 
 unitStr ()
 Returns unit(s) as the product of numerator units divided by the product of denominator units.
 
 valueInRange ($min, $max, $name=null)
 
 valueInRangeWithUnit ($min, $max, $name, $unit)
 

Public Attributes

int null $sourceColumn
 
int $sourceIndex
 
int null $sourceLine
 
string $type
 
const PRECISION = 10
 

Static Public Attributes

static int $precision = self::PRECISION
 

Static Protected Attributes

static array $unitTable
 

Detailed Description

Dimension + optional units.

{

Constructor & Destructor Documentation

◆ __construct()

ScssPhp\ScssPhp\Node\Number::__construct ( $dimension,
$numeratorUnits,
array $denominatorUnits = [] )

Initialize number.

Parameters
int | float$dimension
string[] | string$numeratorUnits
string[]$denominatorUnits

@phpstan-param list<string>|string $numeratorUnits @phpstan-param list<string> $denominatorUnits

Member Function Documentation

◆ assertNoUnits()

ScssPhp\ScssPhp\Node\Number::assertNoUnits ( $varName = null)
Parameters
string | null$varName
Return values
void

◆ assertSameUnitOrUnitless()

ScssPhp\ScssPhp\Node\Number::assertSameUnitOrUnitless ( Number $other)
Parameters
Number$other
Return values
void

◆ assertUnit()

ScssPhp\ScssPhp\Node\Number::assertUnit ( $unit,
$varName = null )
Parameters
string$unit
string | null$varName
Return values
void

◆ coerce()

ScssPhp\ScssPhp\Node\Number::coerce ( array $newNumeratorUnits,
array $newDenominatorUnits )

Returns a copy of this number, converted to the units represented by $newNumeratorUnits and $newDenominatorUnits.

This does not throw an error if this number is unitless and $newNumeratorUnits/$newDenominatorUnits are not empty, or vice versa. Instead, it treats all unitless numbers as convertible to and from all units without changing the value.

Parameters
string[]$newNumeratorUnits
string[]$newDenominatorUnits
Return values
Number

@phpstan-param list<string> $newNumeratorUnits @phpstan-param list<string> $newDenominatorUnits

Exceptions
SassScriptExceptionif this number's units are not compatible with $newNumeratorUnits and $newDenominatorUnits

◆ dividedBy()

ScssPhp\ScssPhp\Node\Number::dividedBy ( Number $other)
Parameters
Number$other
Return values
Number

◆ equals()

ScssPhp\ScssPhp\Node\Number::equals ( Number $other)
Parameters
Number$other
Return values
bool

◆ getDenominatorUnits()

ScssPhp\ScssPhp\Node\Number::getDenominatorUnits ( )
Return values
list<string>

◆ getDimension()

ScssPhp\ScssPhp\Node\Number::getDimension ( )
Return values
float|int

◆ getNumeratorUnits()

ScssPhp\ScssPhp\Node\Number::getNumeratorUnits ( )
Return values
list<string>

◆ greaterThan()

ScssPhp\ScssPhp\Node\Number::greaterThan ( Number $other)
Parameters
Number$other
Return values
bool

◆ greaterThanOrEqual()

ScssPhp\ScssPhp\Node\Number::greaterThanOrEqual ( Number $other)
Parameters
Number$other
Return values
bool

◆ hasUnit()

ScssPhp\ScssPhp\Node\Number::hasUnit ( $unit)

Checks whether the number has exactly this unit.

Parameters
string$unit
Return values
bool

◆ hasUnits()

ScssPhp\ScssPhp\Node\Number::hasUnits ( )

Returns true if the number has any units.

Return values
bool

◆ isComparableTo()

ScssPhp\ScssPhp\Node\Number::isComparableTo ( Number $other)
Parameters
Number$other
Return values
bool

◆ jsonSerialize()

ScssPhp\ScssPhp\Node\Number::jsonSerialize ( )
Return values
mixed

◆ lessThan()

ScssPhp\ScssPhp\Node\Number::lessThan ( Number $other)
Parameters
Number$other
Return values
bool

◆ lessThanOrEqual()

ScssPhp\ScssPhp\Node\Number::lessThanOrEqual ( Number $other)
Parameters
Number$other
Return values
bool

◆ minus()

ScssPhp\ScssPhp\Node\Number::minus ( Number $other)
Parameters
Number$other
Return values
Number

◆ modulo()

ScssPhp\ScssPhp\Node\Number::modulo ( Number $other)
Parameters
Number$other
Return values
Number

◆ offsetExists()

ScssPhp\ScssPhp\Node\Number::offsetExists ( $offset)
Return values
bool

◆ offsetGet()

ScssPhp\ScssPhp\Node\Number::offsetGet ( $offset)
Return values
mixed

◆ offsetSet()

ScssPhp\ScssPhp\Node\Number::offsetSet ( $offset,
$value )
Return values
void

◆ offsetUnset()

ScssPhp\ScssPhp\Node\Number::offsetUnset ( $offset)
Return values
void

◆ output()

ScssPhp\ScssPhp\Node\Number::output ( Compiler $compiler = null)

Output number.

Parameters
ScssPhp\ScssPhp\Compiler$compiler
Return values
string

◆ plus()

ScssPhp\ScssPhp\Node\Number::plus ( Number $other)
Parameters
Number$other
Return values
Number

◆ times()

ScssPhp\ScssPhp\Node\Number::times ( Number $other)
Parameters
Number$other
Return values
Number

◆ unaryMinus()

ScssPhp\ScssPhp\Node\Number::unaryMinus ( )
Return values
Number

◆ unitless()

ScssPhp\ScssPhp\Node\Number::unitless ( )

Returns true if the number is unitless.

Return values
bool

◆ unitStr()

ScssPhp\ScssPhp\Node\Number::unitStr ( )

Returns unit(s) as the product of numerator units divided by the product of denominator units.

Return values
string

◆ valueInRange()

ScssPhp\ScssPhp\Node\Number::valueInRange ( $min,
$max,
$name = null )
Parameters
float | int$min
float | int$max
string | null$name
Return values
float|int
Exceptions
SassScriptException

◆ valueInRangeWithUnit()

ScssPhp\ScssPhp\Node\Number::valueInRangeWithUnit ( $min,
$max,
$name,
$unit )
Parameters
float | int$min
float | int$max
string$name
string$unit
Return values
float|int
Exceptions
SassScriptException

Member Data Documentation

◆ $precision

int ScssPhp\ScssPhp\Node\Number::$precision = self::PRECISION
static
Deprecated
use {Number\PRECISION} instead to read the precision. Configuring it is not supported anymore.

◆ $unitTable

array ScssPhp\ScssPhp\Node\Number::$unitTable
staticprotected
Initial value:
= [
'in' => [
'in' => 1,
'pc' => 6,
'pt' => 72,
'px' => 96,
'cm' => 2.54,
'mm' => 25.4,
'q' => 101.6,
],
'turn' => [
'deg' => 360,
'grad' => 400,
'rad' => 6.28318530717958647692528676,
'turn' => 1,
],
's' => [
's' => 1,
'ms' => 1000,
],
'Hz' => [
'Hz' => 1,
'kHz' => 0.001,
],
'dpi' => [
'dpi' => 1,
'dpcm' => 1 / 2.54,
'dppx' => 1 / 96,
],
]
See also
http://www.w3.org/TR/2012/WD-css3-values-20120308/

@phpstan-var array<string, array<string, float|int>>


The documentation for this class was generated from the following file: