Test Setup Failed
Push — develop ( 01f508...e1be97 )
by Mattias
01:57
created

APIMessage   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 41
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getData() 0 4 1
A hasText() 0 4 1
A getText() 0 7 2
A getResponseData() 0 8 1
A getUpdateId() 0 4 1
1
<?php
2
3
namespace TelegramBot;
4
5
/**
6
 * message from api
7
 */
8
class APIMessage
9
{
10
    private $data;
11
12
    public function __construct($data)
13
    {
14
        $this->data = $data;
15
    }
16
17
    public function getData()
18
    {
19
        return $this->data;
20
    }
21
22
    public function hasText()
23
    {
24
        return isset($this->data['message']['text']);
25
    }
26
27
    public function getText()
28
    {
29
        if (!$this->hasText()) {
30
            return null;
31
        }
32
        return $this->data['message']['text'];
33
    }
34
35
    public function getResponseData($responseText)
36
    {
37
        return [
38
      'chat_id' => $this->data['message']['chat']['id'],
39
      'reply_to_message_id' => $this->data['message']['message_id'],
40
      'text' => $responseText
41
    ];
42
    }
43
44
    public function getUpdateId()
45
    {
46
        return $this->data['update_id'];
47
    }
48
}
49