Inline::addRow()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Smoqadam\Keyboard;
4
5
class Inline {
6
7
  public
8
    $inline_keyboard = [];
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $inline_keyboard.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
9
    
10
  private
11
    $current_row = 0;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $current_row.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
12
  
13
  /**
14
  * Create new row.
15
  *
16
  * @return object
17
  */
18
  public function addRow(){
19
    $this->current_row++;
20
    
21
    return $this;
22
  }
23
  
24
  /**
25
  * Add new button to current row.
26
  *
27
  * @param string $text Label text on the button
28
  * @param string $url Optional. HTTP url to be opened when button is pressed
29
  * @param string $callback_data Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes
30
  * @param string $switch_inline_query Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot‘s username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted.
31
  * @param string $switch_inline_query_current_chat Optional. If set, pressing the button will insert the bot‘s username and the specified inline query in the current chat's input field. Can be empty, in which case only the bot’s username will be inserted.
32
  * @param string $callback_game Optional. Description of the game that will be launched when the user presses the button. NOTE: This type of button must always be the first button in the first row.
33
  * @return object
34
  */
35
  public function addButton(string $text, string $url = '', string $callback_data = '', string $switch_inline_query = '', string $switch_inline_query_current_chat = '', string $callback_game = ''){
36
    $btn['text'] = $text;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$btn was never initialized. Although not strictly required by PHP, it is generally a good practice to add $btn = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
37
    if($url != '')
38
      $btn['url'] = $url;
39
    elseif($callback_data != '')
40
      $btn['callback_data'] = $callback_data;
41
    elseif($switch_inline_query != '')
42
     $btn['switch_inline_query'] = $switch_inline_query;
43
    elseif($switch_inline_query_current_chat != '')
44
      $btn['switch_inline_query_current_chat'] = $switch_inline_query_current_chat;
45
    elseif($callback_game != '')
46
      $btn['callback_game'] = $callback_game;
47
    else
48
      $btn['callback_data'] = $text;
49
      
50
    $this->inline_keyboard[$this->current_row][] = $btn;
51
    
52
    return $this;
53
  }
54
55
}
56