Passed
Push — master ( 627075...c975e5 )
by Chema
02:50
created

createBarronsSiteCrawler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
use Chemaclass\StockTicker\Domain\Crawler\Site\Barrons\BarronsSiteCrawler;
6
use Chemaclass\StockTicker\Domain\Crawler\Site\Barrons\HtmlCrawler;
7
use Chemaclass\StockTicker\Domain\Crawler\Site\FinanceYahoo\FinanceYahooSiteCrawler;
8
use Chemaclass\StockTicker\Domain\Crawler\Site\FinanceYahoo\JsonExtractor;
9
use Chemaclass\StockTicker\Domain\Crawler\Site\Shared\NewsNormalizer;
10
use Chemaclass\StockTicker\Domain\Notifier\Channel\Email\EmailChannel;
11
use Chemaclass\StockTicker\Domain\Notifier\Channel\Slack\HttpSlackClient;
12
use Chemaclass\StockTicker\Domain\Notifier\Channel\Slack\SlackChannel;
13
use Chemaclass\StockTicker\Domain\Notifier\Channel\TwigTemplateGenerator;
14
use Symfony\Component\HttpClient\HttpClient;
15
use Symfony\Component\Mailer\Bridge\Google\Transport\GmailSmtpTransport;
16
use Symfony\Component\Mailer\Mailer;
17
use Twig\Environment;
18
use Twig\Loader\FilesystemLoader;
19
20
require_once dirname(__DIR__) . '/vendor/autoload.php';
21
22
Dotenv\Dotenv::createImmutable(__DIR__)->load();
23
24
/*
25
 * ======================================================
26
 * This `autoload.php` and these functions are just for
27
 * the example usage.
28
 * ======================================================
29
 */
30
31
function createFinanceYahooSiteCrawler(int $maxNewsToFetch = 2): FinanceYahooSiteCrawler
32
{
33
    return new FinanceYahooSiteCrawler([
34
        'NAME' => new JsonExtractor\QuoteSummaryStore\CompanyName(),
35
        'PRICE' => new JsonExtractor\QuoteSummaryStore\RegularMarketPrice(),
36
        'CURRENCY' => new JsonExtractor\QuoteSummaryStore\Currency(),
37
        'CHANGE' => new JsonExtractor\QuoteSummaryStore\RegularMarketChange(),
38
        'CHANGE_PERCENT' => new JsonExtractor\QuoteSummaryStore\RegularMarketChangePercent(),
39
        'TREND' => new JsonExtractor\QuoteSummaryStore\RecommendationTrend(),
40
        'NEWS' => new JsonExtractor\StreamStore\News(new NewsNormalizer(new DateTimeZone('Europe/Berlin'), $maxNewsToFetch)),
0 ignored issues
show
Bug introduced by
The type Chemaclass\StockTicker\D...ractor\StreamStore\News was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
41
        'URL' => new JsonExtractor\RouteStore\ExternalUrl(),
42
    ]);
43
}
44
45
function createBarronsSiteCrawler(int $maxNewsToFetch = 2): BarronsSiteCrawler
46
{
47
    return new BarronsSiteCrawler([
48
        'NEWS' => new HtmlCrawler\News(new NewsNormalizer(new DateTimeZone('Europe/Berlin'), $maxNewsToFetch)),
49
    ]);
50
}
51
52
function createEmailChannel(string $templateName = 'email.twig'): EmailChannel
53
{
54
    return new EmailChannel(
55
        $_ENV['TO_ADDRESS'],
56
        new Mailer(new GmailSmtpTransport(
57
            $_ENV['MAILER_USERNAME'],
58
            $_ENV['MAILER_PASSWORD']
59
        )),
60
        new TwigTemplateGenerator(
61
            new Environment(new FilesystemLoader(__DIR__ . '/templates')),
62
            $templateName
63
        )
64
    );
65
}
66
67
function createSlackChannel(string $templateName = 'slack.twig'): SlackChannel
68
{
69
    return new SlackChannel(
70
        $_ENV['SLACK_DESTINY_CHANNEL_ID'],
71
        new HttpSlackClient(HttpClient::create([
72
            'auth_bearer' => $_ENV['SLACK_BOT_USER_OAUTH_ACCESS_TOKEN'],
73
        ])),
74
        new TwigTemplateGenerator(
75
            new Environment(new FilesystemLoader(__DIR__ . '/templates')),
76
            $templateName
77
        )
78
    );
79
}
80