Skip to content

Commit 613bafb

Browse files
committed
Change variables to snake_case.
1 parent 224f71b commit 613bafb

File tree

4 files changed

+72
-72
lines changed

4 files changed

+72
-72
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ composer require php-telegram-bot/inline-keyboard-pagination:^1.0.0
2828

2929
### Test Data
3030
```php
31-
$items = range(1, 100);
32-
$command = 'testCommand'; // optional. Default: pagination
33-
$selectedPage = 10; // optional. Default: 1
31+
$items = range(1, 100); // required.
32+
$command = 'testCommand'; // optional. Default: pagination
33+
$selected_page = 10; // optional. Default: 1
3434
```
3535

3636
### How To Use
3737
```php
3838
$ikp = new InlineKeyboardPagination($items, $command);
3939
$ikp->setMaxButtons(6);
4040
$ikp->setWrapSelectedButton('< #VALUE# >');
41-
42-
$pagination = $ikp->pagination($selectedPage); //$ikp->setSelectedPage($selectedPage);
41+
42+
$pagination = $ikp->pagination($selected_page); //$ikp->setSelectedPage($selected_page);
4343
```
4444

4545
### Result

src/InlineKeyboardPagination.php

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ class InlineKeyboardPagination implements InlineKeyboardPaginator
1919
/**
2020
* @var integer
2121
*/
22-
private $maxButtons = 5;
22+
private $max_buttons = 5;
2323

2424
/**
2525
* @var integer
2626
*/
27-
private $firstPage = 1;
27+
private $first_page = 1;
2828

2929
/**
3030
* @var integer
3131
*/
32-
private $selectedPage;
32+
private $selected_page;
3333

3434
/**
3535
* @var integer
3636
*/
37-
private $numberOfPages;
37+
private $number_of_pages;
3838

3939
/**
4040
* @var array
@@ -49,18 +49,18 @@ class InlineKeyboardPagination implements InlineKeyboardPaginator
4949
/**
5050
* @var string
5151
*/
52-
private $wrapSelectedButton = '« #VALUE# »';
52+
private $wrap_selected_button = '« #VALUE# »';
5353

5454
/**
5555
* @inheritdoc
5656
* @throws InlineKeyboardPaginationException
5757
*/
58-
public function setMaxButtons(int $maxButtons = 5): InlineKeyboardPagination
58+
public function setMaxButtons(int $max_buttons = 5): InlineKeyboardPagination
5959
{
60-
if ($maxButtons < 5 || $maxButtons > 8) {
60+
if ($max_buttons < 5 || $max_buttons > 8) {
6161
throw new InlineKeyboardPaginationException('Invalid max buttons');
6262
}
63-
$this->maxButtons = $maxButtons;
63+
$this->max_buttons = $max_buttons;
6464

6565
return $this;
6666
}
@@ -69,12 +69,12 @@ public function setMaxButtons(int $maxButtons = 5): InlineKeyboardPagination
6969
* @inheritdoc
7070
* @throws InlineKeyboardPaginationException
7171
*/
72-
public function setWrapSelectedButton(string $wrapSelectedButton = '« #VALUE# »'): InlineKeyboardPagination
72+
public function setWrapSelectedButton(string $wrap_selected_button = '« #VALUE# »'): InlineKeyboardPagination
7373
{
74-
if (false === strpos($wrapSelectedButton, '/#VALUE#/')) {
74+
if (false === strpos($wrap_selected_button, '/#VALUE#/')) {
7575
throw new InlineKeyboardPaginationException('Invalid selected button wrapper');
7676
}
77-
$this->wrapSelectedButton = $wrapSelectedButton;
77+
$this->wrap_selected_button = $wrap_selected_button;
7878
return $this;
7979
}
8080

@@ -92,12 +92,12 @@ public function setCommand(string $command = 'pagination'): InlineKeyboardPagina
9292
* @inheritdoc
9393
* @throws InlineKeyboardPaginationException
9494
*/
95-
public function setSelectedPage(int $selectedPage): InlineKeyboardPagination
95+
public function setSelectedPage(int $selected_page): InlineKeyboardPagination
9696
{
97-
if ($selectedPage < 1 || $selectedPage > $this->numberOfPages) {
97+
if ($selected_page < 1 || $selected_page > $this->number_of_pages) {
9898
throw new InlineKeyboardPaginationException('Invalid selected page');
9999
}
100-
$this->selectedPage = $selectedPage;
100+
$this->selected_page = $selected_page;
101101

102102
return $this;
103103
}
@@ -108,11 +108,11 @@ public function setSelectedPage(int $selectedPage): InlineKeyboardPagination
108108
* @inheritdoc
109109
* @throws InlineKeyboardPaginationException
110110
*/
111-
public function __construct(array $items, string $command = 'pagination', int $selectedPage = 1, int $limit = 3)
111+
public function __construct(array $items, string $command = 'pagination', int $selected_page = 1, int $limit = 3)
112112
{
113-
$this->numberOfPages = $this->countTheNumberOfPage(count($items), $limit);
113+
$this->number_of_pages = $this->countTheNumberOfPage(count($items), $limit);
114114

115-
$this->setSelectedPage($selectedPage);
115+
$this->setSelectedPage($selected_page);
116116

117117
$this->items = $items;
118118
$this->limit = $limit;
@@ -123,10 +123,10 @@ public function __construct(array $items, string $command = 'pagination', int $s
123123
* @inheritdoc
124124
* @throws InlineKeyboardPaginationException
125125
*/
126-
public function paginate(int $selectedPage = null): array
126+
public function paginate(int $selected_page = null): array
127127
{
128-
if ($selectedPage !== null) {
129-
$this->setSelectedPage($selectedPage);
128+
if ($selected_page !== null) {
129+
$this->setSelectedPage($selected_page);
130130
}
131131
return [
132132
'items' => $this->getPreparedItems(),
@@ -141,20 +141,20 @@ protected function generateKeyboard(): array
141141
{
142142
$buttons = [];
143143

144-
if ($this->numberOfPages > $this->maxButtons) {
144+
if ($this->number_of_pages > $this->max_buttons) {
145145

146-
$buttons[] = $this->generateButton($this->firstPage);
146+
$buttons[] = $this->generateButton($this->first_page);
147147

148148
$range = $this->generateRange();
149149

150150
for ($i = $range['from']; $i < $range['to']; $i++) {
151151
$buttons[] = $this->generateButton($i);
152152
}
153153

154-
$buttons[] = $this->generateButton($this->numberOfPages);
154+
$buttons[] = $this->generateButton($this->number_of_pages);
155155

156156
} else {
157-
for ($i = 1; $i <= $this->numberOfPages; $i++) {
157+
for ($i = 1; $i <= $this->number_of_pages; $i++) {
158158
$buttons[] = $this->generateButton($i);
159159
}
160160
}
@@ -166,41 +166,41 @@ protected function generateKeyboard(): array
166166
*/
167167
protected function generateRange(): array
168168
{
169-
$numberOfIntermediateButtons = $this->maxButtons - 2;
169+
$number_of_intermediate_buttons = $this->max_buttons - 2;
170170

171-
if ($this->selectedPage == $this->firstPage) {
171+
if ($this->selected_page == $this->first_page) {
172172
$from = 2;
173-
$to = $from + $numberOfIntermediateButtons;
174-
} elseif ($this->selectedPage == $this->numberOfPages) {
175-
$from = $this->numberOfPages - $numberOfIntermediateButtons;
176-
$to = $this->numberOfPages;
173+
$to = $from + $number_of_intermediate_buttons;
174+
} elseif ($this->selected_page == $this->number_of_pages) {
175+
$from = $this->number_of_pages - $number_of_intermediate_buttons;
176+
$to = $this->number_of_pages;
177177
} else {
178-
if (($this->selectedPage + $numberOfIntermediateButtons) > $this->numberOfPages) {
179-
$from = $this->numberOfPages - $numberOfIntermediateButtons;
180-
$to = $this->numberOfPages;
181-
} elseif (($this->selectedPage - 2) < $this->firstPage) {
182-
$from = $this->selectedPage;
183-
$to = $this->selectedPage + $numberOfIntermediateButtons;
178+
if (($this->selected_page + $number_of_intermediate_buttons) > $this->number_of_pages) {
179+
$from = $this->number_of_pages - $number_of_intermediate_buttons;
180+
$to = $this->number_of_pages;
181+
} elseif (($this->selected_page - 2) < $this->first_page) {
182+
$from = $this->selected_page;
183+
$to = $this->selected_page + $number_of_intermediate_buttons;
184184
} else {
185-
$from = $this->selectedPage - 1;
186-
$to = $this->selectedPage + 2;
185+
$from = $this->selected_page - 1;
186+
$to = $this->selected_page + 2;
187187
}
188188
}
189189
return compact('from', 'to');
190190
}
191191

192192
/**
193-
* @param int $nextPage
193+
* @param int $next_page
194194
*
195195
* @return array
196196
*/
197-
protected function generateButton(int $nextPage): array
197+
protected function generateButton(int $next_page): array
198198
{
199-
$label = "$nextPage";
200-
$callbackData = $this->generateCallbackData($nextPage);
199+
$label = "$next_page";
200+
$callbackData = $this->generateCallbackData($next_page);
201201

202-
if ($nextPage === $this->selectedPage) {
203-
$label = str_replace('#VALUE#', $label, $this->wrapSelectedButton);
202+
if ($next_page === $this->selected_page) {
203+
$label = str_replace('#VALUE#', $label, $this->wrap_selected_button);
204204
}
205205
return [
206206
'text' => $label,
@@ -209,13 +209,13 @@ protected function generateButton(int $nextPage): array
209209
}
210210

211211
/**
212-
* @param int $nextPage
212+
* @param int $next_page
213213
*
214214
* @return string
215215
*/
216-
protected function generateCallbackData(int $nextPage): string
216+
protected function generateCallbackData(int $next_page): string
217217
{
218-
return "$this->command?currentPage=$this->selectedPage&nextPage=$nextPage";
218+
return "$this->command?currentPage=$this->selected_page&nextPage=$next_page";
219219
}
220220

221221
/**
@@ -233,19 +233,19 @@ protected function getPreparedItems(): array
233233
*/
234234
protected function getOffset(): int
235235
{
236-
return ($this->limit * $this->selectedPage) - $this->limit;
236+
return ($this->limit * $this->selected_page) - $this->limit;
237237
}
238238

239239
/**
240-
* @param $itemsLength
240+
* @param $items_length
241241
* @param $limit
242242
*
243243
* @return int
244244
*/
245-
protected function countTheNumberOfPage($itemsLength, $limit): int
245+
protected function countTheNumberOfPage($items_length, $limit): int
246246
{
247-
$numberOfPages = ceil($itemsLength / $limit);
247+
$number_of_pages = ceil($items_length / $limit);
248248

249-
return (int) $numberOfPages;
249+
return (int) $number_of_pages;
250250
}
251251
}

src/InlineKeyboardPaginator.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010
interface InlineKeyboardPaginator
1111
{
1212
/**
13-
* @param int $maxButtons
13+
* @param int $max_buttons
1414
*
1515
* @return InlineKeyboardPagination
1616
*/
17-
public function setMaxButtons(int $maxButtons = 5): InlineKeyboardPagination;
17+
public function setMaxButtons(int $max_buttons = 5): InlineKeyboardPagination;
1818

1919
/**
2020
* >#VALUE#<, <#VALUE#>, |#VALUE#| etc...
2121
*
22-
* @param string $wrapSelectedButton
22+
* @param string $wrap_selected_button
2323
*
2424
* @return InlineKeyboardPagination
2525
*/
26-
public function setWrapSelectedButton(string $wrapSelectedButton = '« #VALUE# »'): InlineKeyboardPagination;
26+
public function setWrapSelectedButton(string $wrap_selected_button = '« #VALUE# »'): InlineKeyboardPagination;
2727

2828
/**
2929
* @param string $command
@@ -33,26 +33,26 @@ public function setWrapSelectedButton(string $wrapSelectedButton = '« #VALUE#
3333
public function setCommand(string $command = 'pagination'): InlineKeyboardPagination;
3434

3535
/**
36-
* @param int $selectedPage
36+
* @param int $selected_page
3737
*
3838
* @return InlineKeyboardPagination
3939
*/
40-
public function setSelectedPage(int $selectedPage): InlineKeyboardPagination;
40+
public function setSelectedPage(int $selected_page): InlineKeyboardPagination;
4141

4242
/**
4343
* InlineKeyboardPaginator constructor.
4444
*
4545
* @param array $items
4646
* @param string $command
47-
* @param int $selectedPage
47+
* @param int $selected_page
4848
* @param int $limit
4949
*/
50-
public function __construct(array $items, string $command, int $selectedPage, int $limit);
50+
public function __construct(array $items, string $command, int $selected_page, int $limit);
5151

5252
/**
53-
* @param int $selectedPage
53+
* @param int $selected_page
5454
*
5555
* @return array
5656
*/
57-
public function paginate(int $selectedPage = null): array;
57+
public function paginate(int $selected_page = null): array;
5858
}

tests/InlineKeyboardPaginationTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class InlineKeyboardPaginationTest extends \PHPUnit\Framework\TestCase
1717
/**
1818
* @var int
1919
*/
20-
private $selectedPage;
20+
private $selected_page;
2121

2222
/**
2323
* @var string
@@ -38,12 +38,12 @@ public function __construct()
3838

3939
$this->items = range(1, 100);
4040
$this->command = 'testCommand';
41-
$this->selectedPage = random_int(1, 15);
41+
$this->selected_page = random_int(1, 15);
4242
}
4343

4444
public function test_valid_constructor()
4545
{
46-
$ikp = new InlineKeyboardPagination($this->items, $this->command, $this->selectedPage, $this->limit);
46+
$ikp = new InlineKeyboardPagination($this->items, $this->command, $this->selected_page, $this->limit);
4747

4848
$data = $ikp->paginate();
4949

@@ -65,7 +65,7 @@ public function test_invalid_constructor()
6565

6666
public function test_valid_paginate()
6767
{
68-
$ikp = new InlineKeyboardPagination($this->items, $this->command, $this->selectedPage, $this->limit);
68+
$ikp = new InlineKeyboardPagination($this->items, $this->command, $this->selected_page, $this->limit);
6969

7070
$length = (int) ceil(count($this->items) / $this->limit);
7171

@@ -81,7 +81,7 @@ public function test_valid_paginate()
8181
*/
8282
public function test_invalid_paginate()
8383
{
84-
$ikp = new InlineKeyboardPagination($this->items, $this->command, $this->selectedPage, $this->limit);
84+
$ikp = new InlineKeyboardPagination($this->items, $this->command, $this->selected_page, $this->limit);
8585

8686
$length = (int) ceil(count($this->items) / $this->limit) + 1;
8787

0 commit comments

Comments
 (0)