Sobak/scrawler

View on GitHub
src/Block/Matcher/RegexHtmlMatcher.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

declare(strict_types=1);

namespace Sobak\Scrawler\Block\Matcher;

use Sobak\Scrawler\Support\Utils;

class RegexHtmlMatcher extends AbstractMatcher implements SingleMatcherInterface
{
    public function match(): ?string
    {
        $responseBody = $this->getCrawler()->html();

        preg_match($this->getMatchBy(), $responseBody, $matches);

        return isset($matches['result']) ? Utils::trimWhitespace($matches['result']) : null;
    }
}