Passed
Push — master ( fbc72e...fd2e1d )
by Alexey
04:39
created

SimpleSender::sendMessage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 12
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 2
crap 6
1
<?php
2
3
namespace Skobkin\Bundle\PointToolsBundle\Service\Telegram;
4
5
use GuzzleHttp\Exception\ClientException;
6
use unreal4u\TelegramAPI\Telegram\Methods\SendMessage;
7
use unreal4u\TelegramAPI\TgLog;
8
9
/**
10
 * Service which sends simple messages to Telegram users
11
 */
12
class SimpleSender
13
{
14
    /**
15
     * @var TgLog
16
     */
17
    private $client;
18
19
    /**
20
     * @param TgLog $client
21
     */
22
    public function __construct(TgLog $client)
23
    {
24
        $this->client = $client;
25
    }
26
27
    /**
28
     * Send simple message
29
     *
30
     * @param int $chatId
31
     * @param string $text
32
     *
33
     * @return bool
34
     */
35
    public function sendMessage(int $chatId, string $text): bool
36
    {
37
        $sendMessage = new SendMessage();
38
        $sendMessage->chat_id = $chatId;
0 ignored issues
show
Documentation Bug introduced by
The property $chat_id was declared of type string, but $chatId is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
39
        $sendMessage->text = $text;
40
41
        try {
42
            $this->client->performApiRequest($sendMessage);
43
44
            return true;
45
        } catch (ClientException $e) {
46
            return false;
47
        }
48
    }
49
}