MarketWatchSiteCrawler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 14
c 1
b 0
f 0
dl 0
loc 30
rs 10
ccs 12
cts 12
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A crawl() 0 16 2
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chemaclass\StockTicker\Domain\Crawler\Site\MarketWatch;
6
7
use Chemaclass\StockTicker\Domain\Crawler\SiteCrawlerInterface;
8
use Chemaclass\StockTicker\Domain\ReadModel\Site;
9
use Chemaclass\StockTicker\Domain\ReadModel\Symbol;
10
use Symfony\Contracts\HttpClient\HttpClientInterface;
11
12
final class MarketWatchSiteCrawler implements SiteCrawlerInterface
13
{
14
    private const REQUEST_METHOD = 'GET';
15
16
    private const REQUEST_URL = 'https://www.marketwatch.com/investing/stock/%s';
17
18
    /** @var HtmlCrawlerInterface[] */
19
    private array $crawlers;
20
21 4
    public function __construct(array $crawlers)
22
    {
23 4
        $this->crawlers = $crawlers;
24 4
    }
25
26 4
    public function crawl(HttpClientInterface $httpClient, Symbol $symbol): Site
27
    {
28 4
        $symbol = mb_strtolower($symbol->toString());
29 4
        $url = sprintf(self::REQUEST_URL, $symbol);
30
31
        $html = $httpClient
32 4
            ->request(self::REQUEST_METHOD, $url)
33 4
            ->getContent($throw = false);
34
35 4
        $crawled = [];
36
37 4
        foreach ($this->crawlers as $name => $crawler) {
38 4
            $crawled[$name] = $crawler->crawlHtml($html);
39
        }
40
41 4
        return new Site($crawled);
42
    }
43
}
44