Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions src/Value/Size.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Size extends PrimitiveValue
/**
* @var string|null
*/
private $sUnit;
private $unit;

/**
* @var bool
Expand All @@ -69,15 +69,15 @@ class Size extends PrimitiveValue

/**
* @param float|int|string $size
* @param string|null $sUnit
* @param string|null $unit
* @param bool $bIsColorComponent
* @param int<0, max> $lineNumber
*/
public function __construct($size, $sUnit = null, $bIsColorComponent = false, $lineNumber = 0)
public function __construct($size, $unit = null, $bIsColorComponent = false, $lineNumber = 0)
{
parent::__construct($lineNumber);
$this->size = (float) $size;
$this->sUnit = $sUnit;
$this->unit = $unit;
$this->bIsColorComponent = $bIsColorComponent;
}

Expand Down Expand Up @@ -110,18 +110,18 @@ public static function parse(ParserState $parserState, $bIsColorComponent = fals
}
}

$sUnit = null;
$aSizeUnits = self::getSizeUnits();
foreach ($aSizeUnits as $length => &$aValues) {
$unit = null;
$sizeUnits = self::getSizeUnits();
foreach ($sizeUnits as $length => &$aValues) {
$sKey = \strtolower($parserState->peek($length));
if (\array_key_exists($sKey, $aValues)) {
if (($sUnit = $aValues[$sKey]) !== null) {
if (($unit = $aValues[$sKey]) !== null) {
$parserState->consume($length);
break;
}
}
}
return new Size((float) $size, $sUnit, $bIsColorComponent, $parserState->currentLine());
return new Size((float) $size, $unit, $bIsColorComponent, $parserState->currentLine());
}

/**
Expand All @@ -146,19 +146,19 @@ private static function getSizeUnits()
}

/**
* @param string $sUnit
* @param string $unit
*/
public function setUnit($sUnit): void
public function setUnit($unit): void
{
$this->sUnit = $sUnit;
$this->unit = $unit;
}

/**
* @return string|null
*/
public function getUnit()
{
return $this->sUnit;
return $this->unit;
}

/**
Expand Down Expand Up @@ -193,18 +193,18 @@ public function isColorComponent()
*/
public function isSize(): bool
{
if (\in_array($this->sUnit, self::NON_SIZE_UNITS, true)) {
if (\in_array($this->unit, self::NON_SIZE_UNITS, true)) {
return false;
}
return !$this->isColorComponent();
}

public function isRelative(): bool
{
if (\in_array($this->sUnit, self::RELATIVE_SIZE_UNITS, true)) {
if (\in_array($this->unit, self::RELATIVE_SIZE_UNITS, true)) {
return true;
}
if ($this->sUnit === null && $this->size != 0) {
if ($this->unit === null && $this->size != 0) {
return true;
}
return false;
Expand All @@ -225,6 +225,6 @@ public function render(OutputFormat $outputFormat): string
$size = \preg_match('/[\\d\\.]+e[+-]?\\d+/i', (string) $this->size)
? \preg_replace("/$sPoint?0+$/", '', \sprintf('%f', $this->size)) : (string) $this->size;
return \preg_replace(["/$sPoint/", '/^(-?)0\\./'], ['.', '$1.'], $size)
. ($this->sUnit ?? '');
. ($this->unit ?? '');
}
}