Skip to content

Commit 5f05323

Browse files
authored
Merge pull request #11 from noplanman/updated-pre-release
Improve development configurations, update changelog
2 parents 24c501c + 37e5744 commit 5f05323

11 files changed

+127
-102
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/.idea
2+
/.phpunit.result.cache
23
/composer.phar
3-
/vendor/
4+
/coverage.xml
5+
/phpcs.xml
46
/phpunit.xml
5-
.phpunit.result.cache
7+
/vendor/

.scrutinizer.yml

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
filter:
2-
paths: [src/*]
1+
build:
2+
environment:
3+
php: 7.3.0
4+
nodes:
5+
analysis:
6+
tests:
7+
override:
8+
- php-scrutinizer-run
39

4-
checks:
5-
php:
6-
remove_extra_empty_lines: true
7-
remove_php_closing_tag: true
8-
remove_trailing_whitespace: true
9-
fix_use_statements:
10-
remove_unused: true
11-
preserve_multiple: false
12-
preserve_blanklines: true
13-
order_alphabetically: true
14-
fix_php_opening_tag: true
15-
fix_linefeed: true
16-
fix_line_ending: true
17-
fix_identation_4spaces: true
18-
fix_doc_comments: true
10+
filter:
11+
paths:
12+
- src/

.travis.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@ language: php
44

55
cache:
66
directories:
7-
- "$HOME/.composer/cache"
7+
- vendor
8+
- $HOME/.composer/cache
89

910
php:
1011
- 7.3
1112
- 7.4
1213
- 8.0
1314
- nightly
14-
- hhvm
1515

16-
17-
matrix:
16+
jobs:
1817
allow_failures:
1918
- php: nightly
20-
- php: hhvm
2119
fast_finish: true
2220

2321
notifications:
@@ -34,5 +32,5 @@ script:
3432
- composer check-code
3533
- if [ "$TRAVIS_PHP_VERSION" == "8.0" ]; then composer test-cov; else composer test; fi
3634

37-
after_script:
35+
after_success:
3836
- if [ "$TRAVIS_PHP_VERSION" == "8.0" ]; then composer test-cov-upload; fi

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
55

66
## [Unreleased]
77
### Added
8+
- Bump minimum PHP to 7.3 and support PHP 8. (@MyZik) (#8)
89
### Changed
10+
- Bump development dependencies, update tests.
11+
- Improve all development configurations.
912
### Deprecated
1013
### Removed
1114
### Fixed
1215
### Security
16+
- Minimum PHP 7.3. (@MyZik) (#8)
1317

1418
## [0.1.0] - 2017-09-08
1519
### Added

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,20 @@
1919
## Installation
2020

2121
### Composer
22+
2223
```bash
23-
composer require php-telegram-bot/inline-keyboard-pagination:^1.0.0
24+
composer require php-telegram-bot/inline-keyboard-pagination
2425
```
2526

2627
## Usage
2728

2829
### Test Data
30+
2931
```php
30-
$items = range(1, 100); // required.
31-
$command = 'testCommand'; // optional. Default: pagination
32+
$items = range(1, 100); // required.
33+
$command = 'testCommand'; // optional. Default: pagination
3234
$selectedPage = 10; // optional. Default: 1
33-
$labels = [ // optional. Change button labels (showing defaults)
35+
$labels = [ // optional. Change button labels (showing defaults)
3436
'default' => '%d',
3537
'first' => '« %d',
3638
'previous' => '‹ %d',
@@ -44,6 +46,7 @@ $callbackDataFormat = 'command={COMMAND}&oldPage={OLD_PAGE}&newPage={NEW_PAGE}'
4446
```
4547

4648
### How To Use
49+
4750
```php
4851
// Define inline keyboard pagination.
4952
$ikp = new InlineKeyboardPagination($items, $command);
@@ -68,7 +71,7 @@ if (!empty($pagination['keyboard'])) {
6871
//$pagination['keyboard'][1]['callback_data']; // command=testCommand&oldPage=10&newPage=7
6972

7073
...
71-
$data['reply_markup' => [
74+
$data['reply_markup'] = [
7275
'inline_keyboard' => [
7376
$pagination['keyboard'],
7477
],
@@ -78,6 +81,7 @@ if (!empty($pagination['keyboard'])) {
7881
```
7982

8083
To get the callback data, you can use the provided helper method (only works when using the default callback data format):
84+
8185
```php
8286
// e.g. Callback data.
8387
$callback_data = 'command=testCommand&oldPage=10&newPage=1';
@@ -96,7 +100,7 @@ parse_str($callbackData, $params);
96100

97101
## Code Quality
98102

99-
Run the PHPUnit tests via Composer script.
103+
Run the PHPUnit tests via Composer script.
100104

101105
```bash
102106
composer test
@@ -118,7 +122,7 @@ Project based on [Telegram Bot Pagination][github-lartie-tbp] by [lartie][github
118122
[code-coverage-badge]: https://img.shields.io/codecov/c/github/php-telegram-bot/inline-keyboard-pagination.svg
119123
[code-coverage]: https://codecov.io/gh/php-telegram-bot/inline-keyboard-pagination "Code coverage on Codecov"
120124
[build-status-badge]: https://img.shields.io/travis/php-telegram-bot/inline-keyboard-pagination.svg
121-
[build-status]: https://travis-ci.org/php-telegram-bot/inline-keyboard-pagination "Build status on Travis-CI"
125+
[build-status]: https://travis-ci.com/php-telegram-bot/inline-keyboard-pagination "Build status on Travis-CI"
122126

123127
[latest-version-badge]: https://img.shields.io/packagist/v/php-telegram-bot/inline-keyboard-pagination.svg
124128
[total-downloads-badge]: https://img.shields.io/packagist/dt/php-telegram-bot/inline-keyboard-pagination.svg

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@
2727
"php": "^7.3|^8.0"
2828
},
2929
"require-dev": {
30-
"jakub-onderka/php-parallel-lint": "^0.9.2",
31-
"php-parallel-lint/php-parallel-lint": "v1.2.0",
32-
"phpunit/phpunit": "^9.5.2",
33-
"squizlabs/php_codesniffer": "^3.0"
30+
"php-parallel-lint/php-parallel-lint": "v1.2",
31+
"phpunit/phpunit": "^9.5",
32+
"squizlabs/php_codesniffer": "^3.5"
3433
},
3534
"autoload": {
3635
"psr-4": {
@@ -45,13 +44,14 @@
4544
"scripts": {
4645
"check-code": [
4746
"vendor/bin/parallel-lint . --exclude vendor",
48-
"vendor/bin/phpcs src/ tests/ -snp --standard=psr2 --encoding=utf-8 --report-width=150"
47+
"vendor/bin/phpcs"
4948
],
5049
"test": [
5150
"vendor/bin/phpunit"
5251
],
5352
"test-cov": [
54-
"vendor/bin/phpunit --coverage-clover=clover.xml"
53+
"@putenv XDEBUG_MODE=coverage",
54+
"vendor/bin/phpunit --coverage-clover coverage.xml"
5555
],
5656
"test-cov-upload": [
5757
"curl -s https://codecov.io/bash | bash"

composer.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpcs.xml.dist

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd">
3+
<description>PHP Code Sniffer</description>
4+
5+
<arg value="snp"/>
6+
<arg name="colors"/>
7+
<arg name="extensions" value="php"/>
8+
<arg name="encoding" value="utf-8"/>
9+
<arg name="parallel" value="8"/>
10+
<arg name="report-width" value="150"/>
11+
12+
<file>src/</file>
13+
<file>tests/</file>
14+
15+
<rule ref="PSR12"/>
16+
</ruleset>

phpunit.xml.dist

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="./vendor/autoload.php"
3-
backupGlobals="false"
4-
backupStaticAttributes="false"
5-
beStrictAboutOutputDuringTests="true"
6-
colors="true"
7-
convertErrorsToExceptions="true"
8-
convertNoticesToExceptions="true"
9-
convertWarningsToExceptions="true"
10-
processIsolation="false"
11-
stopOnError="false"
12-
stopOnFailure="false"
13-
verbose="true"
14-
>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd">
3+
<coverage>
4+
<include>
5+
<directory suffix=".php">./src</directory>
6+
</include>
7+
<exclude>
8+
<directory suffix=".php">./src/Exception</directory>
9+
</exclude>
10+
</coverage>
1511
<testsuites>
1612
<testsuite name="Inline Keyboard Pagination Test Suite">
17-
<directory suffix="Test.php">./tests</directory>
13+
<directory>./tests</directory>
1814
</testsuite>
1915
</testsuites>
20-
<filter>
21-
<whitelist processUncoveredFilesFromWhitelist="true">
22-
<directory suffix=".php">./src</directory>
23-
</whitelist>
24-
</filter>
2516
</phpunit>

src/InlineKeyboardPagination.php

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public function setItems(array $items): InlineKeyboardPagination
206206
*/
207207
public function getNumberOfPages(): int
208208
{
209-
return (int)ceil(count($this->items) / $this->itemsPerPage);
209+
return (int) ceil(count($this->items) / $this->itemsPerPage);
210210
}
211211

212212
/**
@@ -309,31 +309,28 @@ protected function generateRange(): array
309309
$numberOfIntermediateButtons = $this->maxButtons - 2;
310310
$numberOfPages = $this->getNumberOfPages();
311311

312+
// @todo: Find a nicer solution for page 3
313+
$from = $this->selectedPage - 1;
314+
$to = $this->selectedPage + ($this->selectedPage === 3 ? $numberOfIntermediateButtons - 1 : 2);
315+
312316
if ($this->selectedPage === 1) {
313317
$from = 2;
314318
$to = $this->maxButtons;
315319
} elseif ($this->selectedPage === $numberOfPages) {
316320
$from = $numberOfPages - $numberOfIntermediateButtons;
317321
$to = $numberOfPages;
318-
} else {
319-
if ($this->selectedPage < 3) {
320-
$from = $this->selectedPage;
321-
$to = $this->selectedPage + $numberOfIntermediateButtons;
322-
} elseif (($numberOfPages - $this->selectedPage) < 3) {
323-
$from = $numberOfPages - $numberOfIntermediateButtons;
324-
$to = $numberOfPages;
325-
} else {
326-
// @todo: Find a nicer solution for page 3
327-
if ($this->forceButtonCount) {
328-
$from = $this->selectedPage - floor($numberOfIntermediateButtons / 2);
329-
$to = $this->selectedPage + ceil(
330-
$numberOfIntermediateButtons / 2
331-
) + ($this->selectedPage === 3 && $this->maxButtons > 5);
332-
} else {
333-
$from = $this->selectedPage - 1;
334-
$to = $this->selectedPage + ($this->selectedPage === 3 ? $numberOfIntermediateButtons - 1 : 2);
335-
}
336-
}
322+
} elseif ($this->selectedPage < 3) {
323+
$from = $this->selectedPage;
324+
$to = $this->selectedPage + $numberOfIntermediateButtons;
325+
} elseif (($numberOfPages - $this->selectedPage) < 3) {
326+
$from = $numberOfPages - $numberOfIntermediateButtons;
327+
$to = $numberOfPages;
328+
} elseif ($this->forceButtonCount) {
329+
$from = $this->selectedPage -
330+
floor($numberOfIntermediateButtons / 2);
331+
$to = $this->selectedPage +
332+
ceil($numberOfIntermediateButtons / 2) +
333+
(int) ($this->selectedPage === 3 && $this->maxButtons > 5);
337334
}
338335

339336
return compact('from', 'to');
@@ -349,7 +346,7 @@ protected function generateRange(): array
349346
protected function generateButton(int $page): array
350347
{
351348
return [
352-
'text' => (string)$page,
349+
'text' => (string) $page,
353350
'callback_data' => $this->generateCallbackData($page),
354351
];
355352
}
@@ -393,10 +390,11 @@ protected function getOffset(): int
393390
/**
394391
* Get the parameters from the callback query.
395392
*
393+
* @todo Possibly make it work for custom formats too?
394+
*
396395
* @param string $data
397396
*
398397
* @return array
399-
* @todo Possibly make it work for custom formats too?
400398
*/
401399
public static function getParametersFromCallbackData(string $data): array
402400
{

0 commit comments

Comments
 (0)