MattermostClientFactory::createClient()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of forecast.it.fill project.
7
 * (c) Patrick Jaja <[email protected]>
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace ForecastAutomation\MattermostClient;
13
14
use ForecastAutomation\Kernel\AbstractFactory;
15
use ForecastAutomation\MattermostClient\Business\MattermostApi;
16
use ForecastAutomation\MattermostClient\Shared\Dto\MattermostConfigDto;
17
use GuzzleHttp\Client;
18
19
class MattermostClientFactory extends AbstractFactory
20
{
21
    public function createMattermostConfigDto(): MattermostConfigDto
22
    {
23
        return new MattermostConfigDto(
24
            $_ENV['MATTERMOST_HOST'],
25
            $_ENV['MATTERMOST_USER_ID'],
26
            $_ENV['MATTERMOST_PASSWORD'],
27
            $_ENV['MATTERMOST_TEAM_ID'],
28
        );
29
    }
30
31
    public function createMattermostApi(): MattermostApi
32
    {
33
        return new MattermostApi(
34
            $this->createClient(),
35
            $this->createMattermostConfigDto(),
36
        );
37
    }
38
39
    public function createClient(): Client
40
    {
41
        return new Client(['base_uri' => (string) $_ENV['MATTERMOST_HOST']]);
42
    }
43
}
44