From d5944e6082a1bcc0bfea68706fc07b87557423dd Mon Sep 17 00:00:00 2001 From: Jake Hotson Date: Tue, 6 Oct 2026 03:24:40 +0100 Subject: [PATCH] [TASK] Rename `Size::isSize()` to `isLength()` This reflects the current W3C nomenclature. `isSize()` is marked as deprecated and now simply calls its replacement, for which some unit tests are added. Resolves #1644. --- CHANGELOG.md | 5 +++ src/Value/Size.php | 16 ++++++-- tests/ParserTest.php | 4 +- tests/Unit/Value/SizeTest.php | 76 ++++++++++++++++++++++++++++------- 4 files changed, 80 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9ed8412..ce92a204 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,8 +16,13 @@ Please also have a look at our ### Changed +- `Size::isSize()` is renamed to `isLength()` (#1645) + ### Deprecated +- `Size::isSize()` is deprecated; use `isLength()` instead; it is a direct + replacement (#1645) + ### Removed ### Fixed diff --git a/src/Value/Size.php b/src/Value/Size.php index 42a39607..3c0d10a0 100644 --- a/src/Value/Size.php +++ b/src/Value/Size.php @@ -216,12 +216,12 @@ public function isColorComponent(): bool } /** - * Returns whether the number stored in this Size really represents a size (as in a length of something on screen). - * - * Returns `false` if the unit is an angle, a duration, a frequency, a resolution, or the number is a component in + * @return bool + * `true` if the stored number represents a length, e.g. of something on screen; + * `false` if the unit is an angle, a duration, a frequency, a resolution, or the number is a component in * a `Color` object. */ - public function isSize(): bool + public function isLength(): bool { if (\in_array($this->unit, self::NON_SIZE_UNITS, true)) { return false; @@ -229,6 +229,14 @@ public function isSize(): bool return !$this->isColorComponent(); } + /** + * @deprecated in version 9.6, will be removed in v10.0. Use `isLength()` instead, which is a direct replacement. + */ + public function isSize(): bool + { + return $this->isLength(); + } + public function isRelative(): bool { if (\in_array($this->unit, self::RELATIVE_SIZE_UNITS, true)) { diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 491de0cc..0b381378 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -360,7 +360,7 @@ public function slashedValues(): void $document->render() ); foreach ($document->getAllValues(null) as $value) { - if ($value instanceof Size && $value->isSize() && !$value->isRelative()) { + if ($value instanceof Size && $value->isLength() && !$value->isRelative()) { $value->setSize($value->getSize() * 3); } } @@ -412,7 +412,7 @@ public function functionSyntax(): void self::assertSame($expected, $document->render()); foreach ($document->getAllValues(null, null, true) as $value) { - if ($value instanceof Size && $value->isSize()) { + if ($value instanceof Size && $value->isLength()) { $value->setSize($value->getSize() * 3); } } diff --git a/tests/Unit/Value/SizeTest.php b/tests/Unit/Value/SizeTest.php index 7b70cc7f..afa4b565 100644 --- a/tests/Unit/Value/SizeTest.php +++ b/tests/Unit/Value/SizeTest.php @@ -39,11 +39,11 @@ public function isValue(): void } /** - * @return array + * @return array */ - public static function provideUnit(): array + public static function provideLengthUnit(): array { - $units = [ + return self::mapUnitListForDataProvider([ 'px', 'pt', 'pc', @@ -95,6 +95,15 @@ public static function provideUnit(): array 'cqb', 'cqmin', 'cqmax', + ]); + } + + /** + * @return array + */ + public static function provideNonLengthUnit(): array + { + return self::mapUnitListForDataProvider([ 'deg', 'grad', 'rad', @@ -107,17 +116,7 @@ public static function provideUnit(): array 'dpcm', 'dppx', 'x', - ]; - - return \array_combine( - $units, - \array_map( - static function (string $unit): array { - return [$unit]; - }, - $units - ) - ); + ]); } /** @@ -125,7 +124,8 @@ static function (string $unit): array { * * @param non-empty-string $unit * - * @dataProvider provideUnit + * @dataProvider provideLengthUnit + * @dataProvider provideNonLengthUnit */ public function parsesUnit(string $unit): void { @@ -134,6 +134,34 @@ public function parsesUnit(string $unit): void self::assertSame($unit, $parsedSize->getUnit()); } + /** + * @test + * + * @param non-empty-string $unit + * + * @dataProvider provideLengthUnit + */ + public function isLengthReturnsTrueForLengthUnit(string $unit): void + { + $parsedSize = Size::parse(new ParserState('1' . $unit, Settings::create())); + + self::assertTrue($parsedSize->isLength()); + } + + /** + * @test + * + * @param non-empty-string $unit + * + * @dataProvider provideNonLengthUnit + */ + public function isLengthReturnsFalseForNonLengthUnit(string $unit): void + { + $parsedSize = Size::parse(new ParserState('1' . $unit, Settings::create())); + + self::assertFalse($parsedSize->isLength()); + } + /** * @test */ @@ -169,4 +197,22 @@ public function getArrayRepresentationIncludesUnit(): void self::assertSame('px', $result['unit']); } + + /** + * @param array $units + * + * @return array + */ + private static function mapUnitListForDataProvider(array $units): array + { + return \array_combine( + $units, + \array_map( + static function (string $unit): array { + return [$unit]; + }, + $units + ) + ); + } }