Completed
Push — develop ( 005f78...818c3c )
by Armando
10s
created

ReplyKeyboardMarkup   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 7
c 4
b 0
f 0
lcom 0
cbo 2
dl 0
loc 52
ccs 0
cts 18
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C __construct() 0 22 7
1
<?php
2
/**
3
 * This file is part of the TelegramBot package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * Written by Marco Boretto <[email protected]>
11
 */
12
13
namespace Longman\TelegramBot\Entities;
14
15
use Longman\TelegramBot\Exception\TelegramException;
16
17
class ReplyKeyboardMarkup extends Entity
18
{
19
    /**
20
     * @var array
21
     */
22
    protected $keyboard;
23
24
    /**
25
     * @var bool
26
     */
27
    protected $resize_keyboard;
28
29
    /**
30
     * @var bool
31
     */
32
    protected $one_time_keyboard;
33
34
    /**
35
     * @var bool
36
     */
37
    protected $selective;
38
39
    /**
40
     * ReplyKeyboardMarkup constructor.
41
     *
42
     * @param array $data
43
     *
44
     * @throws \Longman\TelegramBot\Exception\TelegramException
45
     */
46
    public function __construct(array $data = [])
47
    {
48
        if (!isset($data['keyboard'])) {
49
            throw new TelegramException('Keyboard field is empty!');
50
        }
51
52
        if (!is_array($data['keyboard'])) {
53
            throw new TelegramException('Keyboard field is not an array!');
54
        }
55
56
        foreach ($data['keyboard'] as $item) {
57
            if (!is_array($item)) {
58
                throw new TelegramException('Keyboard subfield is not an array!');
59
            }
60
        }
61
        $this->keyboard = $data['keyboard'];
62
63
        //Set the object members from the passed data params
64
        foreach (['resize_keyboard', 'one_time_keyboard', 'selective'] as $param) {
65
            $this->$param = isset($data[$param]) ? (bool)$data[$param] : false;
66
        }
67
    }
68
}
69