From f4ddd6457f8f89b624454083d2e4b30ca6297982 Mon Sep 17 00:00:00 2001 From: Jake Hotson Date: Sat, 10 May 2025 01:49:33 +0100 Subject: [PATCH] [CLEANUP] Check for `Positionable` in `lineNumbersParsing()` test Now the interface has been added, it is no longer necessary to check the object is one of a long list of types. Also use the new `getLineNumber()` instead of the deprecated `getLineNo()`. --- tests/ParserTest.php | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/tests/ParserTest.php b/tests/ParserTest.php index ffda6b8c..656d943b 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -14,6 +14,7 @@ use Sabberworm\CSS\Parsing\OutputException; use Sabberworm\CSS\Parsing\SourceException; use Sabberworm\CSS\Parsing\UnexpectedTokenException; +use Sabberworm\CSS\Position\Positionable; use Sabberworm\CSS\Property\AtRule; use Sabberworm\CSS\Property\Charset; use Sabberworm\CSS\Property\CSSNamespace; @@ -975,31 +976,12 @@ public function lineNumbersParsing(): void $actual = []; foreach ($document->getContents() as $contentItem) { - // PHPStan can see what `assertInstanceOf()` does, - // but does not understand `LogicalOr` with multiple `IsIntanceOf` constraints. - // So a more explicit type check is required. - // TODO: tidy this up when an interface with `getLineNo()` is added. - if ( - !$contentItem instanceof Charset - && !$contentItem instanceof CSSList - && !$contentItem instanceof CSSNamespace - && !$contentItem instanceof Import - && !$contentItem instanceof RuleSet - ) { - self::fail('Content item is not of an expected type. It\'s a `' . \get_class($contentItem) . '`.'); - } - $actual[$contentItem->getLineNo()] = [\get_class($contentItem)]; + self::assertInstanceOf(Positionable::class, $contentItem); + $actual[$contentItem->getLineNumber()] = [\get_class($contentItem)]; if ($contentItem instanceof KeyFrame) { foreach ($contentItem->getContents() as $block) { - if ( - !$block instanceof CSSList - && !$block instanceof RuleSet - ) { - self::fail( - 'KeyFrame content item is not of an expected type. It\'s a `' . \get_class($block) . '`.' - ); - } - $actual[$contentItem->getLineNo()][] = $block->getLineNo(); + self::assertInstanceOf(Positionable::class, $block); + $actual[$contentItem->getLineNumber()][] = $block->getLineNumber(); } } }