Completed
Push — master ( fb9178...7ad21f )
by Robert
07:17
created

MessageSender::toUser()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zored\TelegramBundle\Telegram\Command;
6
7
use Zored\Telegram\Entity\Control\Message\MarkdownMessage;
8
use Zored\Telegram\Entity\Control\Peer\PeerFactory;
9
use Zored\Telegram\TelegramApiInterface;
10
11
final class MessageSender
12
{
13
    /**
14
     * @var TelegramApiInterface
15
     */
16
    private $api;
17
18
    public function __construct(TelegramApiInterface $api)
19
    {
20
        $this->api = $api;
21
    }
22
23
    /**
24
     * @throws \Zored\TelegramBundle\Telegram\Command\Exception\PeerMessageSendException
25
     */
26
    public function send(string $search, string $messageContent): void
27
    {
28
        $dialogs = $this->api->getDialogs();
29
        $this->api->sendMessage(PeerFactory::createByEntity(
30
            $dialogs->findUserByFullName($search) ??
0 ignored issues
show
Bug introduced by
It seems like $dialogs->findUserByFull...indChatByTitle($search) can also be of type null; however, parameter $entity of Zored\Telegram\Entity\Co...ctory::createByEntity() does only seem to accept Zored\Telegram\Entity\General\AbstractEntity, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

30
            /** @scrutinizer ignore-type */ $dialogs->findUserByFullName($search) ??
Loading history...
31
            $dialogs->findChatByTitle($search)
32
        ), new MarkdownMessage($messageContent));
33
    }
34
}
35