diff --git a/.travis.yml b/.travis.yml index a1b9250..7df9d99 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,27 +5,29 @@ cache: - $HOME/.composer/cache php: + - '7.1' - '7.2' - '7.3' - '7.4' + - '8.0' jobs: fast_finish: true include: - - php: 7.4 - env: COVERAGE=true + - php: 8.0 + env: XDEBUG_MODE=coverage before_script: - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - chmod +x ./cc-test-reporter script: - - "phpunit --coverage-text --coverage-clover build/logs/clover.xml" + - "phpunit --coverage-text --coverage-clover clover.xml" - if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then ./cc-test-reporter after-build -t clover --exit-code $TRAVIS_TEST_RESULT; fi allow_failures: - - env: COVERAGE=true + - env: XDEBUG_MODE=coverage before_script: # disable xdebug if not coverage - - if [[ $COVERAGE == "" ]]; then phpenv config-rm xdebug.ini; fi + - if [[ $XDEBUG_MODE == "" ]]; then phpenv config-rm xdebug.ini; fi install: - composer install --no-interaction --prefer-dist --no-ansi --no-progress --no-suggest diff --git a/composer.json b/composer.json index dbe2de4..885c13e 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php" : "^7.1" + "php" : "^7.1 || ^8.0" }, "autoload": { "psr-4": { @@ -18,7 +18,7 @@ } }, "require-dev": { - "phpunit/phpunit": "^7.5.20|^8|^9", + "phpunit/phpunit": "^7.5.20 || ^8 || ^9", "phpstan/phpstan": "^0.12.5", "arxeiss/coding-standards": "^0.7.0" } diff --git a/phpcs.xml b/phpcs.xml index 17b6bce..df0250f 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -5,6 +5,8 @@ ./src ./tests + + diff --git a/phpunit.xml b/phpunit.xml index 463a98d..c572a64 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,20 +1,23 @@ - + + + + + ./src + + ./tests/Units - - - ./src - - diff --git a/src/Paginator.php b/src/Paginator.php index 73cef0e..5e1d5a8 100644 --- a/src/Paginator.php +++ b/src/Paginator.php @@ -213,6 +213,9 @@ protected function applyBreakpointClasses( } [$leftDotsIndex, $middleIndex, $rightDotsIndex] = $this->getDotsIndex($paginator); + if ($middleIndex === null) { + $middleIndex = 0; + } // There are no dots on the left side but breakpoint should hide some of the elements on the left side if (!$leftDotsIndex && $this->currentPage > (int)\ceil($maxVisible / 2)) { @@ -256,7 +259,7 @@ private function addButtonClasses( $hideFromRight = $toHide; } elseif ($leftDotsIndex && !$rightDotsIndex) { $hideFromLeft = $toHide; - } elseif ($leftDotsIndex && $rightDotsIndex) { + } elseif ($leftDotsIndex) { // "&& $rightDotsIndex" has no effect on condition and is removed // How many buttons around actual index should be visible $middleVisibleOffset = (int)\ceil((\count($paginator->buttons) - $toHide - 5) / 2); $hideFromLeft = $middleIndex - 2 - $middleVisibleOffset; @@ -279,7 +282,7 @@ private function addButtonClasses( } /** - * @return array + * @return array */ protected function getDotsIndex(Pages $paginator): array { @@ -308,16 +311,17 @@ static function ($button, $key) use ($middleIndex) { /** * Search index in array by condition in callback * - * @param mixed[] $arr - * @return mixed + * @param mixed[] $arr */ - private static function arrayCallbackSearch(array $arr, callable $searchCallback) + private static function arrayCallbackSearch(array $arr, callable $searchCallback): ?int { foreach ($arr as $key => $item) { if (\call_user_func($searchCallback, $item, $key)) { return $key; } } + + return null; } /**