Skip to content

Commit d82adae

Browse files
committed
fixup! [FEATURE] Support for inserting an item in a CSSList
1 parent 1a16a49 commit d82adae

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

src/CSSList/CSSList.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,21 +295,18 @@ public function splice($iOffset, $iLength = null, $mReplacement = null)
295295
}
296296

297297
/**
298-
* Insert an item before or after its sibling.
298+
* Insert an item before its sibling.
299299
*
300300
* @param RuleSet|CSSList|Import|Charset $oItem The item.
301301
* @param RuleSet|CSSList|Import|Charset $oSibling The sibling.
302-
* @param $sPosition The position.
303302
*/
304-
public function insert($oItem, $oSibling, string $sPosition = 'before'): void
303+
public function insertBefore($oItem, $oSibling): void
305304
{
306305
$iIndex = in_array($oSibling, $this->aContents);
307306
if ($iIndex === false) {
308307
$this->append($oItem);
309-
} elseif ($sPosition === 'before') {
310-
$this->replace($oSibling, array($oItem, $oSibling));
311308
} else {
312-
$this->replace($oSibling, array($oSibling, $oItem));
309+
$this->replace($oSibling, array($oItem, $oSibling));
313310
}
314311
}
315312

tests/CSSList/DocumentTest.php

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

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

9595
$bogusOne = new DeclarationBlock();
@@ -110,21 +110,12 @@ public static function insertDataProvider(): \Generator
110110
'initialContent' => [$bogusOne, $oSibling, $bogusTwo],
111111
'oItem' => $oItem,
112112
'oSibling' => $oSibling,
113-
'position' => 'before',
114113
'expectedContent' => [$bogusOne, $oItem, $oSibling, $bogusTwo],
115114
];
116-
yield 'insert after' => [
117-
'initialContent' => [$bogusOne, $oSibling, $bogusTwo],
118-
'oItem' => $oItem,
119-
'oSibling' => $oSibling,
120-
'position' => 'after',
121-
'expectedContent' => [$bogusOne, $oSibling, $oItem, $bogusTwo],
122-
];
123115
yield 'append if not found' => [
124116
'initialContent' => [$bogusOne, $oSibling, $bogusTwo],
125117
'oItem' => $oItem,
126118
'oSibling' => $oOrphan,
127-
'position' => 'before',
128119
'expectedContent' => [$bogusOne, $oSibling, $bogusTwo, $oItem],
129120
];
130121
}
@@ -138,21 +129,20 @@ public static function insertDataProvider(): \Generator
138129
* @param $sPosition
139130
* @param $expectedContent
140131
*
141-
* @dataProvider insertDataProvider
132+
* @dataProvider insertBeforeDataProvider
142133
*/
143-
public function insertContent(
134+
public function insertContentBefore(
144135
array $initialContent,
145136
DeclarationBlock $oItem,
146137
DeclarationBlock $oSibling,
147-
string $sPosition,
148138
array $expectedContent
149139
) {
150140

151141
$this->subject->setContents($initialContent);
152142

153143
self::assertCount(3, $this->subject->getContents());
154144

155-
$this->subject->insert($oItem, $oSibling, $sPosition);
145+
$this->subject->insertBefore($oItem, $oSibling);
156146

157147
self::assertCount(4, $this->subject->getContents());
158148
self::assertSame($expectedContent, $this->subject->getContents());

0 commit comments

Comments
 (0)