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

HttpSlackClient::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
crap 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