Skip to content

Commit a6325dc

Browse files
committed
Mini code changes and spacing.
1 parent 613bafb commit a6325dc

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/InlineKeyboardPagination.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function setWrapSelectedButton(string $wrap_selected_button = '« #VALUE#
7575
throw new InlineKeyboardPaginationException('Invalid selected button wrapper');
7676
}
7777
$this->wrap_selected_button = $wrap_selected_button;
78+
7879
return $this;
7980
}
8081

@@ -128,6 +129,7 @@ public function paginate(int $selected_page = null): array
128129
if ($selected_page !== null) {
129130
$this->setSelectedPage($selected_page);
130131
}
132+
131133
return [
132134
'items' => $this->getPreparedItems(),
133135
'keyboard' => $this->generateKeyboard(),
@@ -158,6 +160,7 @@ protected function generateKeyboard(): array
158160
$buttons[] = $this->generateButton($i);
159161
}
160162
}
163+
161164
return $buttons;
162165
}
163166

@@ -168,10 +171,10 @@ protected function generateRange(): array
168171
{
169172
$number_of_intermediate_buttons = $this->max_buttons - 2;
170173

171-
if ($this->selected_page == $this->first_page) {
174+
if ($this->selected_page === $this->first_page) {
172175
$from = 2;
173176
$to = $from + $number_of_intermediate_buttons;
174-
} elseif ($this->selected_page == $this->number_of_pages) {
177+
} elseif ($this->selected_page === $this->number_of_pages) {
175178
$from = $this->number_of_pages - $number_of_intermediate_buttons;
176179
$to = $this->number_of_pages;
177180
} else {
@@ -186,6 +189,7 @@ protected function generateRange(): array
186189
$to = $this->selected_page + 2;
187190
}
188191
}
192+
189193
return compact('from', 'to');
190194
}
191195

@@ -202,6 +206,7 @@ protected function generateButton(int $next_page): array
202206
if ($next_page === $this->selected_page) {
203207
$label = str_replace('#VALUE#', $label, $this->wrap_selected_button);
204208
}
209+
205210
return [
206211
'text' => $label,
207212
'callback_data' => $callbackData,
@@ -223,17 +228,15 @@ protected function generateCallbackData(int $next_page): string
223228
*/
224229
protected function getPreparedItems(): array
225230
{
226-
$offset = $this->getOffset();
227-
228-
return array_slice($this->items, $offset, $this->limit);
231+
return array_slice($this->items, $this->getOffset(), $this->limit);
229232
}
230233

231234
/**
232235
* @return int
233236
*/
234237
protected function getOffset(): int
235238
{
236-
return ($this->limit * $this->selected_page) - $this->limit;
239+
return $this->limit * ($this->selected_page - 1);
237240
}
238241

239242
/**
@@ -244,8 +247,6 @@ protected function getOffset(): int
244247
*/
245248
protected function countTheNumberOfPage($items_length, $limit): int
246249
{
247-
$number_of_pages = ceil($items_length / $limit);
248-
249-
return (int) $number_of_pages;
250+
return (int) ceil($items_length / $limit);
250251
}
251252
}

tests/InlineKeyboardPaginationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public function __construct()
3636
{
3737
parent::__construct();
3838

39-
$this->items = range(1, 100);
40-
$this->command = 'testCommand';
39+
$this->items = range(1, 100);
40+
$this->command = 'testCommand';
4141
$this->selected_page = random_int(1, 15);
4242
}
4343

0 commit comments

Comments
 (0)