Completed
Push — master ( c9c9bd...d36537 )
by Robert
02:25
created

MessageSender::findPeer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 7
rs 9.4285
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
use Zored\TelegramBundle\Telegram\Command\Exception\PeerMessageSendException;
0 ignored issues
show
Bug introduced by
The type Zored\TelegramBundle\Tel...eerMessageSendException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
13
final class MessageSender
14
{
15
    /**
16
     * @var TelegramApiInterface
17
     */
18
    private $api;
19
20
    public function __construct(TelegramApiInterface $api)
21
    {
22
        $this->api = $api;
23
    }
24
25
    /**
26
     * @throws PeerMessageSendException
27
     */
28
    public function send(string $search, string $messageContent): void
29
    {
30
        $this->api->sendMessage(
31
            $this->findPeer($search),
32
            new MarkdownMessage($messageContent)
33
        );
34
    }
35
36
    /**
37
     * @throws PeerMessageSendException
38
     */
39
    private function findPeer(string $search): PeerInterface
40
    {
41
        $dialogs = $this->api->getDialogs();
42
43
        return PeerFactory::createByEntity(
44
            $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

44
            /** @scrutinizer ignore-type */ $dialogs->findUserByFullName($search) ??
Loading history...
45
            $dialogs->findChatByTitle($search)
46
        );
47
    }
48
}
49