Skip to content

Commit ab39541

Browse files
committed
Update PHP minimum version to 8.0 and dependencies to latest compatible version
1 parent d85fcd5 commit ab39541

File tree

10 files changed

+46
-38
lines changed

10 files changed

+46
-38
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
16-
php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3']
16+
php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4']
1717
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
1818
steps:
1919
- name: Checkout
@@ -28,7 +28,7 @@ jobs:
2828
run: php -v
2929
- name: Cache Composer packages
3030
id: composer-cache
31-
uses: actions/cache@v3
31+
uses: actions/cache@v4
3232
with:
3333
path: vendor
3434
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}

.scrutinizer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ build:
1111
command: phpcs-run
1212
use_website_config: false
1313
environment:
14-
php: 7.4.0
14+
php: 8.0
1515
filter:
1616
excluded_paths:
1717
- 'tests/*'

README.MD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/c60bca19b93347159cfd771a8dc9de7e)](https://app.codacy.com/gh/platine-php/pagination/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
1313

1414
### Requirements
15-
- **PHP >= 7.4**, **PHP 8**
15+
- **PHP >= 8.0**
1616

1717
### Installation
1818
#### Using composer (recommended)

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
},
2020

2121
"require": {
22-
"php": "^7.4 || ^8"
22+
"php": "^8"
2323
},
2424

2525
"require-dev": {
2626
"phpmd/phpmd": "@stable",
27-
"phpstan/phpstan": "^1.8",
28-
"phpunit/phpunit": "^9.5",
29-
"platine-php/dev": "^1.0",
27+
"phpstan/phpstan": "^2.0",
28+
"phpunit/phpunit": "^9.6",
29+
"platine-php/dev": "^2.0",
3030
"squizlabs/php_codesniffer": "3.*"
3131
},
3232

src/Page.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
namespace Platine\Pagination;
4949

5050
/**
51-
* Class Page
51+
* @class Page
5252
* @package Platine\Pagination
5353
*/
5454
class Page
@@ -57,7 +57,7 @@ class Page
5757
* The page number
5858
* @var int|string
5959
*/
60-
protected $number;
60+
protected int|string $number;
6161

6262
/**
6363
* The page URL
@@ -77,7 +77,7 @@ class Page
7777
* @param string|null $url
7878
* @param bool $current
7979
*/
80-
public function __construct($number, ?string $url, bool $current = false)
80+
public function __construct(int|string $number, ?string $url, bool $current = false)
8181
{
8282
$this->number = $number;
8383
$this->url = $url;
@@ -88,7 +88,7 @@ public function __construct($number, ?string $url, bool $current = false)
8888
* Return the page number
8989
* @return int|string
9090
*/
91-
public function getNumber()
91+
public function getNumber(): int|string
9292
{
9393
return $this->number;
9494
}

src/Pagination.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@
5050
use InvalidArgumentException;
5151
use Platine\Pagination\Renderer\DefaultRenderer;
5252
use Platine\Pagination\UrlGenerator\SimpleUrlGenerator;
53+
use Stringable;
5354

5455
/**
55-
* Class Pagination
56+
* @class Pagination
5657
* @package Platine\Pagination
5758
*/
58-
class Pagination
59+
class Pagination implements Stringable
5960
{
6061
/**
6162
* The URL generator instance
@@ -120,13 +121,8 @@ public function __construct(
120121
?UrlGeneratorInterface $urlGenerator = null,
121122
?RendererInterface $renderer = null
122123
) {
123-
$this->urlGenerator = $urlGenerator
124-
? $urlGenerator
125-
: new SimpleUrlGenerator();
126-
127-
$this->renderer = $renderer
128-
? $renderer
129-
: new DefaultRenderer();
124+
$this->urlGenerator = $urlGenerator ?? new SimpleUrlGenerator();
125+
$this->renderer = $renderer ?? new DefaultRenderer();
130126

131127
$this->updateTotalPages();
132128
}
@@ -160,7 +156,7 @@ public function getNextPage(): ?int
160156
public function getNextUrl(): ?string
161157
{
162158
if ($this->hasNextPage()) {
163-
return $this->getPageUrl($this->getNextPage());
159+
return $this->getPageUrl((int) $this->getNextPage());
164160
}
165161

166162
return null;
@@ -195,7 +191,7 @@ public function getPreviousPage(): ?int
195191
public function getPreviousUrl(): ?string
196192
{
197193
if ($this->hasPreviousPage()) {
198-
return $this->getPageUrl($this->getPreviousPage());
194+
return $this->getPageUrl((int) $this->getPreviousPage());
199195
}
200196

201197
return null;
@@ -412,7 +408,7 @@ public function getMaxPages(): int
412408
/**
413409
* Return the pages links data
414410
*
415-
* @return array<Page>
411+
* @return Page[]
416412
*/
417413
public function getPages(): array
418414
{

src/Renderer/DefaultRenderer.php

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@
4747

4848
namespace Platine\Pagination\Renderer;
4949

50+
use Platine\Pagination\Page;
5051
use Platine\Pagination\Pagination;
5152
use Platine\Pagination\RendererInterface;
5253

5354
/**
54-
* Class DefaultRenderer
55+
* @class DefaultRenderer
5556
* @package Platine\Pagination\Renderer
5657
*/
5758
class DefaultRenderer implements RendererInterface
@@ -68,27 +69,38 @@ public function render(Pagination $pagination): string
6869
$html = '<ul class = "pagination">';
6970

7071
if ($pagination->hasPreviousPage()) {
71-
$html .= '<li><a href = "' . $pagination->getPreviousUrl() . '">&laquo; '
72-
. $pagination->getPreviousText() . '</a></li>';
72+
$html .= sprintf(
73+
'<li><a href = "%s">&laquo; %s</a></li>',
74+
$pagination->getPreviousUrl(),
75+
$pagination->getPreviousText()
76+
);
7377
}
7478

75-
/** @var array<\Platine\Pagination\Page> $pages */
79+
/** @var Page[] $pages */
7680
$pages = $pagination->getPages();
7781

7882
foreach ($pages as $page) {
7983
if ($page->getUrl() !== null) {
80-
$html .= '<li' . ($page->isCurrent() ? ' class = "active"' : '')
81-
. '><a href = "' . $page->getUrl() . '">'
82-
. $page->getNumber() . '</a></li>';
84+
$html .= sprintf(
85+
'<li%s><a href = "%s">%d</a></li>',
86+
$page->isCurrent() ? ' class = "active"' : '',
87+
$page->getUrl(),
88+
$page->getNumber()
89+
);
8390
} else {
84-
$html .= '<li class = "disabled"><span>'
85-
. $page->getNumber() . '</span></li>';
91+
$html .= sprintf(
92+
'<li class = "disabled"><span>%s</span></li>',
93+
$page->getNumber()
94+
);
8695
}
8796
}
8897

8998
if ($pagination->hasNextPage()) {
90-
$html .= '<li><a href = "' . $pagination->getNextUrl() . '">'
91-
. $pagination->getNextText() . ' &raquo;</a></li>';
99+
$html .= sprintf(
100+
'<li><a href = "%s">%s &raquo;</a></li>',
101+
$pagination->getNextUrl(),
102+
$pagination->getNextText()
103+
);
92104
}
93105

94106
$html .= '</ul>';

src/RendererInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
namespace Platine\Pagination;
4949

5050
/**
51-
* Class RendererInterface
51+
* @class RendererInterface
5252
* @package Platine\Pagination
5353
*/
5454
interface RendererInterface

src/UrlGenerator/SimpleUrlGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
use Platine\Pagination\UrlGeneratorInterface;
5151

5252
/**
53-
* Class SimpleUrlGenerator
53+
* @class SimpleUrlGenerator
5454
* @package Platine\Pagination\UrlGenerator
5555
*/
5656
class SimpleUrlGenerator implements UrlGeneratorInterface

src/UrlGeneratorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
namespace Platine\Pagination;
4949

5050
/**
51-
* Class UrlGeneratorInterface
51+
* @class UrlGeneratorInterface
5252
* @package Platine\Pagination
5353
*/
5454
interface UrlGeneratorInterface

0 commit comments

Comments
 (0)