Completed
Pull Request — develop (#288)
by Armando
27:44 queued 12:40
created

ReplyKeyboardMarkup::__construct()   C

Complexity

Conditions 7
Paths 9

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 22
ccs 0
cts 19
cp 0
rs 6.9811
cc 7
eloc 11
nc 9
nop 1
crap 56
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