StockTickerFacade   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 13
c 2
b 0
f 0
dl 0
loc 35
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A crawlStock() 0 10 1
A sendNotifications() 0 13 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