@@ -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}
0 commit comments