Skip to content

Commit

Permalink
Update for PHP 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksagona committed Oct 17, 2023
1 parent 64d0cfa commit 78a11b2
Show file tree
Hide file tree
Showing 12 changed files with 233 additions and 108 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ on:
pull_request:
branches: [ master ]

env:
XDEBUG_MODE: debug,coverage

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
php-versions: [ '7.4', '8.0' ]
php-versions: [ '8.1', '8.2' ]

steps:
- uses: actions/checkout@v3
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
composer.lock
public
script
vendor

kettle
.phpunit.result.cache
.phpunit.cache
2 changes: 1 addition & 1 deletion LICENSE.TXT
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3 Clause License

Copyright (c) 2009-2023, NOLA Interactive, LLC.
Copyright (c) 2009-2024, NOLA Interactive, LLC.
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ Install `pop-paginator` using Composer.

composer require popphp/pop-paginator

Or, require it in your composer.json file

"require": {
"popphp/pop-paginator" : "^4.0.0"
}


BASIC USAGE
-----------

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
}
],
"require": {
"php": ">=7.4.0"
"php": ">=8.1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0.0"
"phpunit/phpunit": "^10.0.0"
},
"autoload": {
"psr-4": {
Expand All @@ -38,7 +38,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "3.1.x-dev"
"dev-master": "4.0.x-dev"
}
}
}
12 changes: 7 additions & 5 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" cacheDirectory=".phpunit.cache">
<coverage>
<report>
<html outputDirectory="/tmp/pop-paginator-cc" lowUpperBound="35" highLowerBound="70"/>
</report>
Expand All @@ -14,4 +11,9 @@
</testsuite>
</testsuites>
<logging/>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
70 changes: 35 additions & 35 deletions src/AbstractPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @link https://github.com/popphp/popphp-framework
* @author Nick Sagona, III <[email protected]>
* @copyright Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com)
* @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
* @license http://www.popphp.org/license New BSD License
*/

Expand All @@ -19,66 +19,66 @@
* @category Pop
* @package Pop\Paginator
* @author Nick Sagona, III <[email protected]>
* @copyright Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com)
* @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
* @license http://www.popphp.org/license New BSD License
* @version 3.1.0
* @version 4.0.0
*/
abstract class AbstractPaginator
abstract class AbstractPaginator implements PaginatorInterface
{

/**
* Total number of items
* @var int
*/
protected $total = 0;
protected int $total = 0;

/**
* Number of items per page
* @var int
*/
protected $perPage = 10;
protected int $perPage = 10;

/**
* Range of pages per page
* @var int
*/
protected $range = 10;
protected int $range = 10;

/**
* Query key
* @var string
*/
protected $queryKey = 'page';
protected string $queryKey = 'page';

/**
* Current page property
* @var int
*/
protected $currentPage = 1;
protected int $currentPage = 1;

/**
* Number of pages property
* @var int
* @var ?int
*/
protected $numberOfPages = null;
protected ?int $numberOfPages = null;

/**
* Current page start index property
* @var int
* @var ?int
*/
protected $start = null;
protected ?int $start = null;

/**
* Current page end index property
* @var int
* @var ?int
*/
protected $end = null;
protected ?int $end = null;

/**
* Page bookends
* @var array
*/
protected $bookends = [
protected array $bookends = [
'start' => '&laquo;',
'previous' => '&lsaquo;',
'next' => '&rsaquo;',
Expand All @@ -94,11 +94,11 @@ abstract class AbstractPaginator
* @param int $perPage
* @param int $range
*/
public function __construct($total, $perPage = 10, $range = 10)
public function __construct(int $total, int $perPage = 10, int $range = 10)
{
$this->total = (int)$total;
$this->perPage = (int)$perPage;
$this->range = (int)$range;
$this->total = $total;
$this->perPage = $perPage;
$this->range = $range;
}

/**
Expand All @@ -107,7 +107,7 @@ public function __construct($total, $perPage = 10, $range = 10)
* @param string $key
* @return AbstractPaginator
*/
public function setQueryKey($key)
public function setQueryKey(string $key): AbstractPaginator
{
$this->queryKey = $key;
return $this;
Expand All @@ -119,7 +119,7 @@ public function setQueryKey($key)
* @param array $bookends
* @return AbstractPaginator
*/
public function setBookends(array $bookends)
public function setBookends(array $bookends): AbstractPaginator
{
if (array_key_exists('start', $bookends)) {
$this->bookends['start'] = $bookends['start'];
Expand All @@ -142,7 +142,7 @@ public function setBookends(array $bookends)
*
* @return int
*/
public function getTotal()
public function getTotal(): int
{
return $this->total;
}
Expand All @@ -152,7 +152,7 @@ public function getTotal()
*
* @return int
*/
public function getPerPage()
public function getPerPage(): int
{
return $this->perPage;
}
Expand All @@ -162,17 +162,17 @@ public function getPerPage()
*
* @return int
*/
public function getRange()
public function getRange(): int
{
return $this->range;
}

/**
* Get the query key
*
* @return int
* @return string
*/
public function getQueryKey()
public function getQueryKey(): string
{
return $this->queryKey;
}
Expand All @@ -182,7 +182,7 @@ public function getQueryKey()
*
* @return int
*/
public function getCurrentPage()
public function getCurrentPage(): int
{
return $this->currentPage;
}
Expand All @@ -192,7 +192,7 @@ public function getCurrentPage()
*
* @return int
*/
public function getNumberOfPages()
public function getNumberOfPages(): int
{
return $this->numberOfPages;
}
Expand All @@ -201,19 +201,19 @@ public function getNumberOfPages()
* Get a bookend
*
* @param string $key
* @return string
* @return string|null
*/
public function getBookend($key)
public function getBookend(string $key): string|null
{
return (isset($this->bookends[$key])) ? $this->bookends[$key] : null;
return $this->bookends[$key] ?? null;
}

/**
* Get the bookends
*
* @return array
*/
public function getBookends()
public function getBookends(): array
{
return $this->bookends;
}
Expand All @@ -224,7 +224,7 @@ public function getBookends()
* @param int $page
* @return array
*/
public function calculateRange($page = 1)
public function calculateRange(int $page = 1): array
{
$this->currentPage = $page;

Expand Down Expand Up @@ -252,7 +252,7 @@ public function calculateRange($page = 1)
}

// Check and calculate for any page ranges.
if (((null === $this->range) || ($this->range > $this->numberOfPages)) && (null === $this->total)) {
if ((($this->range === null) || ($this->range > $this->numberOfPages)) && ($this->total === null)) {
$range = [
'start' => 1,
'end' => $this->numberOfPages,
Expand Down
6 changes: 3 additions & 3 deletions src/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @link https://github.com/popphp/popphp-framework
* @author Nick Sagona, III <[email protected]>
* @copyright Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com)
* @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
* @license http://www.popphp.org/license New BSD License
*/

Expand All @@ -19,8 +19,8 @@
* @category Pop
* @package Pop\Paginator
* @author Nick Sagona, III <[email protected]>
* @copyright Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com)
* @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
* @license http://www.popphp.org/license New BSD License
* @version 3.1.0
* @version 4.0.0
*/
class Exception extends \Exception {}
Loading

0 comments on commit 78a11b2

Please sign in to comment.