MessageSender::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
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\Entity\Control\Peer\PeerInterface;
10
use Zored\Telegram\TelegramApiInterface;
11
12
class MessageSender
13
{
14
    /**
15
     * @var TelegramApiInterface
16
     */
17
    private $api;
18
19
    public function __construct(TelegramApiInterface $api)
20
    {
21
        $this->api = $api;
22
    }
23
24
    public function send(string $search, string $messageContent): void
25
    {
26
        $this->api->sendMessage(
27
            $this->findPeer($search),
28
            new MarkdownMessage($messageContent)
29
        );
30
    }
31
32
    private function findPeer(string $search): PeerInterface
33
    {
34
        $dialogs = $this->api->getDialogs();
35
36
        return PeerFactory::createByEntity(
37
            $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

37
            /** @scrutinizer ignore-type */ $dialogs->findUserByFullName($search) ??
Loading history...
38
            $dialogs->findChatByTitle($search)
39
        );
40
    }
41
}
42