Skip to content

Commit 4e13ad2

Browse files
committed
Removed the depricated depthFirstSearch option
1 parent 9d81490 commit 4e13ad2

File tree

10 files changed

+14
-73
lines changed

10 files changed

+14
-73
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323

2424
### Removed
2525
- Curl interface and curl implementation has been removed.
26+
- Removed support for the depth first search option.
2627

2728
## 2.2.0
2829

src/PHPHtmlParser/Contracts/Selector/SeekerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ interface SeekerInterface
1313
*
1414
* @throws ChildNotFoundException
1515
*/
16-
public function seek(array $nodes, RuleDTO $rule, array $options, bool $depthFirst): array;
16+
public function seek(array $nodes, RuleDTO $rule, array $options): array;
1717
}

src/PHPHtmlParser/Contracts/Selector/SelectorInterface.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ public function __construct(string $selector, ?ParserInterface $parser = null, ?
2121
*/
2222
public function getParsedSelectorCollectionDTO(): ParsedSelectorCollectionDTO;
2323

24-
public function setDepthFirstFind(bool $status): void;
25-
2624
/**
2725
* Attempts to find the selectors starting from the given
2826
* node object.

src/PHPHtmlParser/Dom.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,7 @@ public function find(string $selector, int $nth = null)
259259
{
260260
$this->isLoaded();
261261

262-
$depthFirstSearch = $this->options->get('depthFirstSearch');
263-
if (\is_bool($depthFirstSearch)) {
264-
$result = $this->root->find($selector, $nth, $depthFirstSearch);
265-
} else {
266-
$result = $this->root->find($selector, $nth);
267-
}
262+
$result = $this->root->find($selector, $nth);
268263

269264
return $result;
270265
}

src/PHPHtmlParser/Dom/AbstractNode.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,13 +439,12 @@ public function ancestorByTag(string $tag): AbstractNode
439439
*
440440
* @return mixed|Collection|null
441441
*/
442-
public function find(string $selectorString, ?int $nth = null, bool $depthFirst = false, ?SelectorInterface $selector = null)
442+
public function find(string $selectorString, ?int $nth = null, ?SelectorInterface $selector = null)
443443
{
444444
if (\is_null($selector)) {
445445
$selector = new Selector($selectorString);
446446
}
447447

448-
$selector->setDepthFirstFind($depthFirst);
449448
$nodes = $selector->find($this);
450449

451450
if ($nth !== null) {

src/PHPHtmlParser/Options.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
* @property bool $preserveLineBreaks
1919
* @property bool $removeDoubleSpace
2020
* @property bool $removeSmartyScripts
21-
* @property bool $depthFirstSearch
2221
* @property bool $htmlSpecialCharsDecode
2322
*/
2423
class Options
@@ -38,7 +37,6 @@ class Options
3837
'preserveLineBreaks' => false,
3938
'removeDoubleSpace' => true,
4039
'removeSmartyScripts' => true,
41-
'depthFirstSearch' => false,
4240
'htmlSpecialCharsDecode' => false,
4341
];
4442

@@ -191,21 +189,6 @@ public function setRemoveSmartyScripts(bool $value): self
191189
return $this;
192190
}
193191

194-
/**
195-
* By default this is set to false for legacy support. Setting this to true will change the behavior of find
196-
* to order elements by depth first. This will properly preserve the order of elements as they where in the HTML.
197-
*
198-
* @return Options
199-
*
200-
* @deprecated This option will be removed in version 3.0.0 with the new behavior being as if it was set to true.
201-
*/
202-
public function setDepthFirstSearch(bool $value): self
203-
{
204-
$this->options['depthFirstSearch'] = $value;
205-
206-
return $this;
207-
}
208-
209192
/**
210193
* By default this is set to false. Setting this to true will apply the php function htmlspecialchars_decode too all attribute values and text nodes.
211194
*

src/PHPHtmlParser/Selector/Seeker.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Seeker implements SeekerInterface
2020
* @var InnerNode[] $nodes
2121
* @throws ChildNotFoundException
2222
*/
23-
public function seek(array $nodes, RuleDTO $rule, array $options, bool $depthFirst): array
23+
public function seek(array $nodes, RuleDTO $rule, array $options): array
2424
{
2525
// XPath index
2626
if ($rule->getTag() !== null && \is_numeric($rule->getKey())) {
@@ -80,19 +80,14 @@ public function seek(array $nodes, RuleDTO $rule, array $options, bool $depthFir
8080
// this child failed to be matched
8181
if ($child instanceof InnerNode && $child->hasChildren()
8282
) {
83-
if ($depthFirst) {
84-
if (!isset($options['checkGrandChildren'])
85-
|| $options['checkGrandChildren']
86-
) {
87-
// we have a child that failed but are not leaves.
88-
$matches = $this->seek([$child], $rule, $options, $depthFirst);
89-
foreach ($matches as $match) {
90-
$return[] = $match;
91-
}
83+
if (!isset($options['checkGrandChildren'])
84+
|| $options['checkGrandChildren']
85+
) {
86+
// we have a child that failed but are not leaves.
87+
$matches = $this->seek([$child], $rule, $options);
88+
foreach ($matches as $match) {
89+
$return[] = $match;
9290
}
93-
} else {
94-
// we still want to check its children
95-
$children[] = $child;
9691
}
9792
}
9893

@@ -104,7 +99,7 @@ public function seek(array $nodes, RuleDTO $rule, array $options, bool $depthFir
10499
&& \count($children) > 0
105100
) {
106101
// we have children that failed but are not leaves.
107-
$matches = $this->seek($children, $rule, $options, $depthFirst);
102+
$matches = $this->seek($children, $rule, $options);
108103
foreach ($matches as $match) {
109104
$return[] = $match;
110105
}

src/PHPHtmlParser/Selector/Selector.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ class Selector implements SelectorInterface
2525
*/
2626
private $ParsedSelectorCollectionDTO;
2727

28-
/**
29-
* @var bool
30-
*/
31-
private $depthFirst = false;
32-
3328
/**
3429
* @var SeekerInterface
3530
*/
@@ -61,11 +56,6 @@ public function getParsedSelectorCollectionDTO(): ParsedSelectorCollectionDTO
6156
return $this->ParsedSelectorCollectionDTO;
6257
}
6358

64-
public function setDepthFirstFind(bool $status): void
65-
{
66-
$this->depthFirst = $status;
67-
}
68-
6959
/**
7060
* Attempts to find the selectors starting from the given
7161
* node object.
@@ -87,7 +77,7 @@ public function find(AbstractNode $node): Collection
8777
$options[] = $this->alterNext($rule);
8878
continue;
8979
}
90-
$nodes = $this->seeker->seek($nodes, $rule, $options, $this->depthFirst);
80+
$nodes = $this->seeker->seek($nodes, $rule, $options);
9181
// clear the options
9282
$options = [];
9383
}

tests/DomTest.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -483,19 +483,6 @@ public function testFindOrder()
483483
$dom->load($str);
484484
$images = $dom->find('img');
485485

486-
$this->assertEquals('<img src="http://example.com/second.jpg" />', (string) $images[0]);
487-
}
488-
489-
public function testFindDepthFirstSearch()
490-
{
491-
$str = '<p><img src="http://example.com/first.jpg"></p><img src="http://example.com/second.jpg">';
492-
$dom = new Dom();
493-
$dom->setOptions([
494-
'depthFirstSearch' => true,
495-
]);
496-
$dom->load($str);
497-
$images = $dom->find('img');
498-
499486
$this->assertEquals('<img src="http://example.com/first.jpg" />', (string) $images[0]);
500487
}
501488

tests/OptionsTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public function testSetters()
7070
'preserveLineBreaks' => false,
7171
'removeDoubleSpace' => false,
7272
'removeSmartyScripts' => false,
73-
'depthFirstSearch' => false,
7473
'htmlSpecialCharsDecode' => false,
7574
]);
7675

@@ -101,9 +100,6 @@ public function testSetters()
101100
$options->setRemoveSmartyScripts(true);
102101
$this->assertTrue($options->get('removeSmartyScripts'));
103102

104-
$options->setDepthFirstSearch(true);
105-
$this->assertTrue($options->get('depthFirstSearch'));
106-
107103
$options->setHtmlSpecialCharsDecode(true);
108104
$this->assertTrue($options->get('htmlSpecialCharsDecode'));
109105

@@ -136,9 +132,6 @@ public function testSetters()
136132
$options->setRemoveSmartyScripts(false);
137133
$this->assertFalse($options->get('removeSmartyScripts'));
138134

139-
$options->setDepthFirstSearch(false);
140-
$this->assertFalse($options->get('depthFirstSearch'));
141-
142135
$options->setHtmlSpecialCharsDecode(false);
143136
$this->assertFalse($options->get('htmlSpecialCharsDecode'));
144137
}

0 commit comments

Comments
 (0)