GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 64a210...2d6991 )
by Stan
02:42
created

AbstractEntityEvent::sendMessage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 14
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 14
loc 14
rs 9.4285
cc 2
eloc 9
nc 2
nop 1
1
<?php
2
3
/**
4
 * Abstract entity event class is base class for creating the events for received in response entities. It
5
 * includes methods to be able to quickly get a chat id and reply on message, get parent entity which
6
 * triggered this entity event.
7
 *
8
 * @package Teebot (Telegram bot framework)
9
 *
10
 * @author  Stanislav Drozdov <[email protected]>
11
 */
12
13
namespace Teebot\Command;
14
15
use Teebot\Method\SendMessage;
16
use Teebot\Entity\Message;
17
use Teebot\Entity\AbstractEntity;
18
19
abstract class AbstractEntityEvent
20
{
21
    /** @var AbstractEntity $entity */
22
    protected $entity = null;
23
24
    /**
25
     * Abstract method of each entity event which will be called if certain entity presents in response
26
     * and it's class exists or mapped in the config. 
27
     * 
28
     * @return null|bool
29
     */
30
    abstract public function run();
31
32
    /**
33
     * Returns chat id if the type of calling entity or it's parent is Message
34
     *
35
     * @return null|int
36
     */
37
    public function getChatId()
38
    {
39
        if ($this->entity instanceof Message) {
40
            return $this->entity->getChatId();
41
        }
42
43
        $parent = $this->entity->getParent();
44
45
        if ($parent instanceof Message) {
46
            return $parent->getChatId();
47
        }
48
49
        return null;
50
    }
51
52
    /**
53
     * Sets entity
54
     *
55
     * @param AbstractEntity $entity Entity object
56
     */
57
    public function setEntity(AbstractEntity $entity)
58
    {
59
        $this->entity = $entity;
60
    }
61
62
    /**
63
     * Sends text message to current chat
64
     *
65
     * @param string $text Message text
66
     *
67
     * @return bool|\Teebot\Response
68
     */
69 View Code Duplication
    protected function sendMessage($text)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
    {
71
        $chatId = $this->getChatId();
72
73
        if (!$chatId) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $chatId of type null|integer is loosely compared to false; this is ambiguous if the integer can be zero. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
74
            return false;
75
        }
76
77
        return (new SendMessage())
78
            ->setParent($this->entity)
79
            ->setChatId($chatId)
80
            ->setText($text)
81
            ->trigger();
82
    }
83
84
    /**
85
     * Replies on the message
86
     *
87
     * @param SendMessage $sendMessage Object of the SendMessage method
88
     *
89
     * @return bool|\Teebot\Response
90
     */
91 View Code Duplication
    protected function reply(SendMessage $sendMessage) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
92
        $chatId = $this->getChatId();
93
94
        if (!$chatId) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $chatId of type null|integer is loosely compared to false; this is ambiguous if the integer can be zero. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
95
            return false;
96
        }
97
98
        return $sendMessage
99
            ->setParent($this->entity)
100
            ->setChatId($chatId)
101
            ->trigger();
102
    }
103
}
104