Completed
Pull Request — develop (#291)
by Armando
15:42
created

InlineKeyboard   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 51.61 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 16
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B validate() 16 16 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
11
namespace Longman\TelegramBot\Entities;
12
13
use Longman\TelegramBot\Exception\TelegramException;
14
15
/**
16
 * Class InlineKeyboard
17
 *
18
 * @link https://core.telegram.org/bots/api#inlinekeyboardmarkup
19
 */
20
class InlineKeyboard extends Keyboard
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function __construct($data = [])
26
    {
27
        $data = call_user_func_array([$this, 'createFromParams'], func_get_args());
28
        parent::__construct($data);
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 View Code Duplication
    protected function validate()
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...
35
    {
36
        $inline_keyboard = $this->getProperty('inline_keyboard');
37
38
        if ($inline_keyboard !== null) {
39
            if (!is_array($inline_keyboard)) {
40
                throw new TelegramException('Inline Keyboard field is not an array!');
41
            }
42
43
            foreach ($inline_keyboard as $item) {
44
                if (!is_array($item)) {
45
                    throw new TelegramException('Inline Keyboard subfield is not an array!');
46
                }
47
            }
48
        }
49
    }
50
}
51