Skip to content

Add type annotations for Size #324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2021
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
45 changes: 45 additions & 0 deletions src/Value/Size.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Sabberworm\CSS\OutputFormat;
use Sabberworm\CSS\Parsing\ParserState;
use Sabberworm\CSS\Parsing\UnexpectedEOFException;
use Sabberworm\CSS\Parsing\UnexpectedTokenException;

class Size extends PrimitiveValue
{
Expand All @@ -29,12 +31,27 @@ class Size extends PrimitiveValue
*/
private static $SIZE_UNITS = null;

/**
* @var float
*/
private $fSize;

/**
* @var string|null
*/
private $sUnit;

/**
* @var bool
*/
private $bIsColorComponent;

/**
* @param float|int|string $fSize
* @param string|null $sUnit
* @param bool $bIsColorComponent
* @param int $iLineNo
*/
public function __construct($fSize, $sUnit = null, $bIsColorComponent = false, $iLineNo = 0)
{
parent::__construct($iLineNo);
Expand All @@ -43,6 +60,14 @@ public function __construct($fSize, $sUnit = null, $bIsColorComponent = false, $
$this->bIsColorComponent = $bIsColorComponent;
}

/**
* @param bool $bIsColorComponent
*
* @return Size
*
* @throws UnexpectedEOFException
* @throws UnexpectedTokenException
*/
public static function parse(ParserState $oParserState, $bIsColorComponent = false)
{
$sSize = '';
Expand Down Expand Up @@ -92,26 +117,43 @@ private static function getSizeUnits()
return self::$SIZE_UNITS;
}

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

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

/**
* @param float|int|string $fSize
*/
public function setSize($fSize)
{
$this->fSize = (float)$fSize;
}

/**
* @return float
*/
public function getSize()
{
return $this->fSize;
}

/**
* @return bool
*/
public function isColorComponent()
{
return $this->bIsColorComponent;
Expand All @@ -130,6 +172,9 @@ public function isSize()
return !$this->isColorComponent();
}

/**
* @return bool
*/
public function isRelative()
{
if (in_array($this->sUnit, self::RELATIVE_SIZE_UNITS, true)) {
Expand Down