Skip to content

Commit

Permalink
Clean up the code
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Dec 6, 2024
1 parent 762e112 commit 673573c
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use DOMElement;
use DOMDocument;
use DOMXPath;
use InvalidArgumentException;
use Illuminate\Support\Collection;
use Illuminate\Testing\Assert as PHPUnit;
Expand Down Expand Up @@ -80,12 +81,11 @@ public function getElementUsingQuery(string $selector): TestableHtmlElement
*/
public function getElementsByClass(string $class): Collection
{
$xpath = new \DOMXPath($this->document); // Use the existing DOMDocument
$xpath = new DOMXPath($this->document);
$nodeList = $xpath->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' $class ')]");

$collection = collect();
foreach ($nodeList as $node) {
// Ensure we are only adding DOMElement objects to the collection.
if ($node instanceof DOMElement) {
$collection->push($this->parseNodeRecursive($node));
}
Expand Down

0 comments on commit 673573c

Please sign in to comment.