Skip to content

Commit 310ba83

Browse files
committed
fixup! [FEATURE] Support for inserting an item in a CSSList
1 parent ea38679 commit 310ba83

File tree

2 files changed

+22
-27
lines changed

2 files changed

+22
-27
lines changed

src/CSSList/CSSList.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,18 +297,17 @@ public function splice($iOffset, $iLength = null, $mReplacement = null)
297297
}
298298

299299
/**
300-
* Insert an item before its sibling.
300+
* Inserts an item before its sibling.
301301
*
302-
* @param RuleSet|CSSList|Import|Charset $oItem The item.
303-
* @param RuleSet|CSSList|Import|Charset $oSibling The sibling.
302+
* @param RuleSet|CSSList|Import|Charset $oItem
303+
* @param RuleSet|CSSList|Import|Charset $oSibling
304304
*/
305305
public function insertBefore($oItem, $oSibling): void
306306
{
307-
$iIndex = in_array($oSibling, $this->aContents);
308-
if ($iIndex === false) {
307+
if (in_array($oSibling, $this->aContents, true) === false) {
309308
$this->append($oItem);
310309
} else {
311-
$this->replace($oSibling, array($oItem, $oSibling));
310+
$this->replace($oSibling, [$oItem, $oSibling]);
312311
}
313312
}
314313

tests/CSSList/DocumentTest.php

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ public function setContentsReplacesContentsSetInPreviousCall(): void
8787
}
8888

8989
/**
90-
* @return \Generator<array<array<DeclarationBlock>, DeclarationBlock, DeclarationBlock, array<DeclarationBlock>>>
90+
* @return array<string, array<string, DeclarationBlock|array<int, DeclarationBlock>>>
9191
*/
92-
public static function insertBeforeDataProvider(): \Generator
92+
public static function insertContentBeforeInsertsContentBeforeSibblingOrAppendsIfSibblingNotFoundDataProvider(): array
9393
{
9494

9595
$bogusOne = new DeclarationBlock();
@@ -106,32 +106,28 @@ public static function insertBeforeDataProvider(): \Generator
106106
$oOrphan = new DeclarationBlock();
107107
$oOrphan->setSelectors('.forever-alone');
108108

109-
yield 'insert before' => [
110-
'initialContent' => [$bogusOne, $oSibling, $bogusTwo],
111-
'oItem' => $oItem,
112-
'oSibling' => $oSibling,
113-
'expectedContent' => [$bogusOne, $oItem, $oSibling, $bogusTwo],
114-
];
115-
yield 'append if not found' => [
116-
'initialContent' => [$bogusOne, $oSibling, $bogusTwo],
117-
'oItem' => $oItem,
118-
'oSibling' => $oOrphan,
119-
'expectedContent' => [$bogusOne, $oSibling, $bogusTwo, $oItem],
120-
];
109+
return [
110+
'insert before' => [
111+
'initialContent' => [$bogusOne, $oSibling, $bogusTwo],
112+
'oItem' => $oItem,
113+
'oSibling' => $oSibling,
114+
'expectedContent' => [$bogusOne, $oItem, $oSibling, $bogusTwo],
115+
],
116+
'append if not found' => [
117+
'initialContent' => [$bogusOne, $oSibling, $bogusTwo],
118+
'oItem' => $oItem,
119+
'oSibling' => $oOrphan,
120+
'expectedContent' => [$bogusOne, $oSibling, $bogusTwo, $oItem],
121+
]
122+
];
121123
}
122124

123125
/**
124126
* @test
125127
*
126-
* @param $initialContent
127-
* @param $oItem
128-
* @param $oSibling
129-
* @param $sPosition
130-
* @param $expectedContent
131-
*
132128
* @dataProvider insertBeforeDataProvider
133129
*/
134-
public function insertContentBefore(
130+
public function insertContentBeforeInsertsContentBeforeSibblingOrAppendsIfSibblingNotFound(
135131
array $initialContent,
136132
DeclarationBlock $oItem,
137133
DeclarationBlock $oSibling,

0 commit comments

Comments
 (0)