Skip to content

Commit 76044ef

Browse files
authored
Merge pull request MyIntervals#324 from oliverklee/task/types/size
Add type annotations for `Size`
2 parents 7f6d782 + 4aa6e2d commit 76044ef

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/Value/Size.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Sabberworm\CSS\OutputFormat;
66
use Sabberworm\CSS\Parsing\ParserState;
7+
use Sabberworm\CSS\Parsing\UnexpectedEOFException;
8+
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
79

810
class Size extends PrimitiveValue
911
{
@@ -29,12 +31,27 @@ class Size extends PrimitiveValue
2931
*/
3032
private static $SIZE_UNITS = null;
3133

34+
/**
35+
* @var float
36+
*/
3237
private $fSize;
3338

39+
/**
40+
* @var string|null
41+
*/
3442
private $sUnit;
3543

44+
/**
45+
* @var bool
46+
*/
3647
private $bIsColorComponent;
3748

49+
/**
50+
* @param float|int|string $fSize
51+
* @param string|null $sUnit
52+
* @param bool $bIsColorComponent
53+
* @param int $iLineNo
54+
*/
3855
public function __construct($fSize, $sUnit = null, $bIsColorComponent = false, $iLineNo = 0)
3956
{
4057
parent::__construct($iLineNo);
@@ -43,6 +60,14 @@ public function __construct($fSize, $sUnit = null, $bIsColorComponent = false, $
4360
$this->bIsColorComponent = $bIsColorComponent;
4461
}
4562

63+
/**
64+
* @param bool $bIsColorComponent
65+
*
66+
* @return Size
67+
*
68+
* @throws UnexpectedEOFException
69+
* @throws UnexpectedTokenException
70+
*/
4671
public static function parse(ParserState $oParserState, $bIsColorComponent = false)
4772
{
4873
$sSize = '';
@@ -92,26 +117,43 @@ private static function getSizeUnits()
92117
return self::$SIZE_UNITS;
93118
}
94119

120+
/**
121+
* @param string $sUnit
122+
*
123+
* @return void
124+
*/
95125
public function setUnit($sUnit)
96126
{
97127
$this->sUnit = $sUnit;
98128
}
99129

130+
/**
131+
* @return string|null
132+
*/
100133
public function getUnit()
101134
{
102135
return $this->sUnit;
103136
}
104137

138+
/**
139+
* @param float|int|string $fSize
140+
*/
105141
public function setSize($fSize)
106142
{
107143
$this->fSize = (float)$fSize;
108144
}
109145

146+
/**
147+
* @return float
148+
*/
110149
public function getSize()
111150
{
112151
return $this->fSize;
113152
}
114153

154+
/**
155+
* @return bool
156+
*/
115157
public function isColorComponent()
116158
{
117159
return $this->bIsColorComponent;
@@ -130,6 +172,9 @@ public function isSize()
130172
return !$this->isColorComponent();
131173
}
132174

175+
/**
176+
* @return bool
177+
*/
133178
public function isRelative()
134179
{
135180
if (in_array($this->sUnit, self::RELATIVE_SIZE_UNITS, true)) {

0 commit comments

Comments
 (0)