StockTickerFacade::crawlStock()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
c 2
b 0
f 0
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chemaclass\StockTicker;
6
7
use Chemaclass\StockTicker\Domain\Crawler\CrawlResult;
8
use Chemaclass\StockTicker\Domain\Notifier\NotifierPolicy;
9
use Chemaclass\StockTicker\Domain\Notifier\NotifyResult;
10
use Gacela\Framework\AbstractFacade;
11
12
/**
13
 * @method StockTickerFactory getFactory()
14
 */
15
final class StockTickerFacade extends AbstractFacade
16
{
17
    private const DEFAULT_MAX_NEWS_TO_FETCH = 9;
18
19
    /**
20
     * @param string[] $channelNames
21
     */
22 2
    public function sendNotifications(
23
        array $channelNames,
24
        NotifierPolicy $policy,
25
        int $maxNewsToFetch = self::DEFAULT_MAX_NEWS_TO_FETCH,
26
    ): NotifyResult {
27 2
        $channels = $this->getFactory()
28 2
            ->createChannels($channelNames);
29
30 2
        $crawlResult = $this->crawlStock($policy->symbols(), $maxNewsToFetch);
31
32 2
        return $this->getFactory()
33 2
            ->createNotifier($policy, ...$channels)
34 2
            ->notify($crawlResult);
35
    }
36
37
    /**
38
     * @param string[] $symbols
39
     */
40 4
    public function crawlStock(
41
        array $symbols,
42
        int $maxNewsToFetch = self::DEFAULT_MAX_NEWS_TO_FETCH,
43
    ): CrawlResult {
44 4
        $siteCrawlers = $this->getFactory()
45 4
            ->createSiteCrawlers($maxNewsToFetch);
46
47 4
        return $this->getFactory()
48 4
            ->createQuoteCrawler(...$siteCrawlers)
49 4
            ->crawlStock(...$symbols);
50
    }
51
}
52