Skip to content

Commit

Permalink
Add PHP 8 (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
arxeiss authored May 11, 2021
1 parent 05b57d5 commit 2ece20c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 25 deletions.
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
}
],
"require": {
"php" : "^7.1"
"php" : "^7.1 || ^8.0"
},
"autoload": {
"psr-4": {
"ResponsivePagination\\": "src"
}
},
"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"
}
Expand Down
2 changes: 2 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<file>./src</file>
<file>./tests</file>

<config name="php_version" value="70000"/>

<arg name="basepath" value="."/> <!-- Strip file basepath from report -->
<arg name="colors"/>
<arg value="p"/><!-- Display progress in report -->
Expand Down
29 changes: 16 additions & 13 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
testdox="true">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
testdox="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">

<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Units">
<directory suffix="Test.php">./tests/Units</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
14 changes: 9 additions & 5 deletions src/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand All @@ -279,7 +282,7 @@ private function addButtonClasses(
}

/**
* @return array<int>
* @return array<?int>
*/
protected function getDotsIndex(Pages $paginator): array
{
Expand Down Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 2ece20c

Please sign in to comment.