Skip to content

Commit 9e18840

Browse files
authored
[CLEANUP] Check for Positionable in lineNumbersParsing() test (#1257)
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()`.
1 parent bddb086 commit 9e18840

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

tests/ParserTest.php

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Sabberworm\CSS\Parsing\OutputException;
1515
use Sabberworm\CSS\Parsing\SourceException;
1616
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
17+
use Sabberworm\CSS\Position\Positionable;
1718
use Sabberworm\CSS\Property\AtRule;
1819
use Sabberworm\CSS\Property\Charset;
1920
use Sabberworm\CSS\Property\CSSNamespace;
@@ -975,31 +976,12 @@ public function lineNumbersParsing(): void
975976

976977
$actual = [];
977978
foreach ($document->getContents() as $contentItem) {
978-
// PHPStan can see what `assertInstanceOf()` does,
979-
// but does not understand `LogicalOr` with multiple `IsIntanceOf` constraints.
980-
// So a more explicit type check is required.
981-
// TODO: tidy this up when an interface with `getLineNo()` is added.
982-
if (
983-
!$contentItem instanceof Charset
984-
&& !$contentItem instanceof CSSList
985-
&& !$contentItem instanceof CSSNamespace
986-
&& !$contentItem instanceof Import
987-
&& !$contentItem instanceof RuleSet
988-
) {
989-
self::fail('Content item is not of an expected type. It\'s a `' . \get_class($contentItem) . '`.');
990-
}
991-
$actual[$contentItem->getLineNo()] = [\get_class($contentItem)];
979+
self::assertInstanceOf(Positionable::class, $contentItem);
980+
$actual[$contentItem->getLineNumber()] = [\get_class($contentItem)];
992981
if ($contentItem instanceof KeyFrame) {
993982
foreach ($contentItem->getContents() as $block) {
994-
if (
995-
!$block instanceof CSSList
996-
&& !$block instanceof RuleSet
997-
) {
998-
self::fail(
999-
'KeyFrame content item is not of an expected type. It\'s a `' . \get_class($block) . '`.'
1000-
);
1001-
}
1002-
$actual[$contentItem->getLineNo()][] = $block->getLineNo();
983+
self::assertInstanceOf(Positionable::class, $block);
984+
$actual[$contentItem->getLineNumber()][] = $block->getLineNumber();
1003985
}
1004986
}
1005987
}

0 commit comments

Comments
 (0)