Passed
Push — master ( 3ec735...0b5e67 )
by Chema
01:36 queued 14s
created

HttpSlackClient   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 21
rs 10
ccs 9
cts 9
cp 1
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A postToChannel() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chemaclass\StockTicker\Domain\Notifier\Channel\Slack;
6
7
use Symfony\Contracts\HttpClient\HttpClientInterface;
8
use Symfony\Contracts\HttpClient\ResponseInterface;
9
10
final class HttpSlackClient implements SlackClientInterface
11
{
12
    public const SLACK_API_POST_MESSAGE = 'https://slack.com/api/chat.postMessage';
13
14
    private HttpClientInterface $client;
15
16 1
    public function __construct(HttpClientInterface $client)
17
    {
18 1
        $this->client = $client;
19 1
    }
20
21 1
    public function postToChannel(string $channel, string $text): ResponseInterface
22
    {
23 1
        return $this->client->request(
24 1
            'POST',
25 1
            self::SLACK_API_POST_MESSAGE,
26
            [
27
                'json' => [
28 1
                    'channel' => $channel,
29 1
                    'text' => $text,
30
                    'as_user' => true,
31
                ],
32
            ]
33
        );
34
    }
35
}
36