| Total Complexity | 9 |
| Total Lines | 59 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | trait ReplyKeyboardMarkup |
||
| 11 | { |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @param int $row |
||
| 15 | * @param KeyboardButton $button |
||
| 16 | * @param bool $first |
||
| 17 | * @return $this |
||
| 18 | */ |
||
| 19 | public function addButton(int $row, KeyboardButton $button, bool $first = false): static |
||
| 20 | { |
||
| 21 | if (empty($this->keyboard[$row])) { |
||
| 22 | throw new InvalidArgumentException('Row not found'); |
||
| 23 | } |
||
| 24 | if ($first) { |
||
| 25 | array_unshift($this->keyboard[$row], $button); |
||
| 26 | return $this; |
||
| 27 | } |
||
| 28 | array_push($this->keyboard[$row], $button); |
||
| 29 | return $this; |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param int $row |
||
| 34 | * @param int $index |
||
| 35 | * @return $this |
||
| 36 | */ |
||
| 37 | public function removeButton(int $row, int $index): static |
||
| 38 | { |
||
| 39 | if (empty($this->keyboard[$row][$index] ?? null)) { |
||
| 40 | return $this; |
||
| 41 | } |
||
| 42 | unset($this->keyboard[$row][$index]); |
||
| 43 | $this->keyboard[$row] = array_values($this->keyboard[$row]); |
||
| 44 | return $this; |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @param KeyboardButton[] $buttons |
||
| 49 | * @param bool $first |
||
| 50 | * @return $this |
||
| 51 | */ |
||
| 52 | public function addRow(array $buttons, bool $first = false): static |
||
| 53 | { |
||
| 54 | if ($first) { |
||
| 55 | array_unshift($this->keyboard, $buttons); |
||
| 56 | return $this; |
||
| 57 | } |
||
| 58 | array_push($this->keyboard, $buttons); |
||
| 59 | return $this; |
||
| 60 | } |
||
| 61 | |||
| 62 | public function removeRow(int $index): static |
||
| 69 | } |
||
| 70 | |||
| 71 | } |