Skip to content

Commit a05cb3b

Browse files
authored
[TASK] Add native type declarations in Size (#1162)
Part of #811
1 parent 34ebb96 commit a05cb3b

File tree

2 files changed

+14
-29
lines changed

2 files changed

+14
-29
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ Please also have a look at our
3333
- Make all non-private properties `@internal` (#886)
3434
- Use more native type declarations and strict mode
3535
(#641, #772, #774, #778, #804, #841, #873, #875, #891, #922, #923, #933, #958,
36-
#964, #967, #1000, #1044, #1134, #1136, #1137, #1139, #1140, #1141, #1145)
36+
#964, #967, #1000, #1044, #1134, #1136, #1137, #1139, #1140, #1141, #1145,
37+
#1162)
3738
- Add visibility to all class/interface constants (#469)
3839

3940
### Deprecated

src/Value/Size.php

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Size extends PrimitiveValue
1717
/**
1818
* vh/vw/vm(ax)/vmin/rem are absolute insofar as they don’t scale to the immediate parent (only the viewport)
1919
*
20-
* @var array<int, string>
20+
* @var list<non-empty-string>
2121
*/
2222
private const ABSOLUTE_SIZE_UNITS = [
2323
'px',
@@ -38,17 +38,17 @@ class Size extends PrimitiveValue
3838
];
3939

4040
/**
41-
* @var array<int, string>
41+
* @var list<non-empty-string>
4242
*/
4343
private const RELATIVE_SIZE_UNITS = ['%', 'em', 'ex', 'ch', 'fr'];
4444

4545
/**
46-
* @var array<int, string>
46+
* @var list<non-empty-string>
4747
*/
4848
private const NON_SIZE_UNITS = ['deg', 'grad', 'rad', 's', 'ms', 'turn', 'Hz', 'kHz'];
4949

5050
/**
51-
* @var array<int, array<string, string>>|null
51+
* @var array<int<1, max>, array<lowercase-string, non-empty-string>>|null
5252
*/
5353
private static $SIZE_UNITS = null;
5454

@@ -69,11 +69,9 @@ class Size extends PrimitiveValue
6969

7070
/**
7171
* @param float|int|string $size
72-
* @param string|null $unit
73-
* @param bool $isColorComponent
7472
* @param int<0, max> $lineNumber
7573
*/
76-
public function __construct($size, $unit = null, $isColorComponent = false, int $lineNumber = 0)
74+
public function __construct($size, ?string $unit = null, bool $isColorComponent = false, int $lineNumber = 0)
7775
{
7876
parent::__construct($lineNumber);
7977
$this->size = (float) $size;
@@ -82,14 +80,12 @@ public function __construct($size, $unit = null, $isColorComponent = false, int
8280
}
8381

8482
/**
85-
* @param bool $isColorComponent
86-
*
8783
* @throws UnexpectedEOFException
8884
* @throws UnexpectedTokenException
8985
*
9086
* @internal since V8.8.0
9187
*/
92-
public static function parse(ParserState $parserState, $isColorComponent = false): Size
88+
public static function parse(ParserState $parserState, bool $isColorComponent = false): Size
9389
{
9490
$size = '';
9591
if ($parserState->comes('-')) {
@@ -125,9 +121,9 @@ public static function parse(ParserState $parserState, $isColorComponent = false
125121
}
126122

127123
/**
128-
* @return array<int, array<string, string>>
124+
* @return array<int<1, max>, array<lowercase-string, non-empty-string>>
129125
*/
130-
private static function getSizeUnits()
126+
private static function getSizeUnits(): array
131127
{
132128
if (!\is_array(self::$SIZE_UNITS)) {
133129
self::$SIZE_UNITS = [];
@@ -146,18 +142,12 @@ private static function getSizeUnits()
146142
return self::$SIZE_UNITS;
147143
}
148144

149-
/**
150-
* @param string $unit
151-
*/
152-
public function setUnit($unit): void
145+
public function setUnit(string $unit): void
153146
{
154147
$this->unit = $unit;
155148
}
156149

157-
/**
158-
* @return string|null
159-
*/
160-
public function getUnit()
150+
public function getUnit(): ?string
161151
{
162152
return $this->unit;
163153
}
@@ -170,18 +160,12 @@ public function setSize($size): void
170160
$this->size = (float) $size;
171161
}
172162

173-
/**
174-
* @return float
175-
*/
176-
public function getSize()
163+
public function getSize(): float
177164
{
178165
return $this->size;
179166
}
180167

181-
/**
182-
* @return bool
183-
*/
184-
public function isColorComponent()
168+
public function isColorComponent(): bool
185169
{
186170
return $this->isColorComponent;
187171
}

0 commit comments

Comments
 (0)