Skip to content

Commit 573ca2e

Browse files
authored
Fix deprecated errors in tests (#575)
* Fix deprecated errors in tests * Safely count all possible types * Support iterable type fully in newer pagerfanta versions * Use psalm 4.30
1 parent 8b9d39b commit 573ca2e

18 files changed

+340
-24
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
fail-fast: true
1010
matrix:
1111
os: [ubuntu-20.04]
12-
php: [7.4, 8.0, 8.1]
12+
php: [7.4, 8.0, 8.1, 8.2, 8.3, 8.4]
1313

1414
name: League - PHP ${{ matrix.php }} on ${{ matrix.os }}
1515

.github/workflows/static.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
php-version: 8.1
3838
extensions: apcu, redis
3939
coverage: none
40-
tools: vimeo/psalm:4.22.0
40+
tools: vimeo/psalm:4.30.0
4141

4242
- name: Download dependencies
4343
uses: ramsey/composer-install@v1

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
composer.lock
22
build
33
vendor
4-
.phpunit.result.cache
4+
.phpunit.result.cache
5+
.idea

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@
2626
"require-dev": {
2727
"doctrine/orm": "^2.5",
2828
"illuminate/contracts": "~5.0",
29+
"laminas/laminas-paginator": "~2.12",
2930
"mockery/mockery": "^1.3",
30-
"pagerfanta/pagerfanta": "~1.0.0",
31+
"pagerfanta/pagerfanta": "~1.0.0|~4.0.0",
3132
"phpstan/phpstan": "^1.4",
3233
"phpunit/phpunit": "^9.5",
3334
"squizlabs/php_codesniffer": "~3.4",
34-
"vimeo/psalm": "^4.22",
35-
"zendframework/zend-paginator": "~2.3"
35+
"vimeo/psalm": "^4.30"
3636
},
3737
"suggest": {
3838
"illuminate/pagination": "The Illuminate Pagination component.",
3939
"pagerfanta/pagerfanta": "Pagerfanta Paginator",
40-
"zendframework/zend-paginator": "Zend Framework Paginator"
40+
"laminas/laminas-paginator": "Laminas Framework Paginator"
4141
},
4242
"autoload": {
4343
"psr-4": {

phpstan.neon.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ parameters:
66
reportUnmatchedIgnoredErrors: false
77
paths:
88
- src
9+
bootstrapFiles:
10+
- test/phpstan.php

psalm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
errorBaseline="psalm.baseline.xml"
99
>
1010
<projectFiles>
11+
<file name="test/phpstan.php" />
1112
<directory name="src" />
1213
<ignoreFiles>
1314
<directory name="vendor" />

src/Manager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Manager
6161
*/
6262
private ScopeFactoryInterface $scopeFactory;
6363

64-
public function __construct(ScopeFactoryInterface $scopeFactory = null)
64+
public function __construct(?ScopeFactoryInterface $scopeFactory = null)
6565
{
6666
$this->scopeFactory = $scopeFactory ?: new ScopeFactory();
6767
}
@@ -72,7 +72,7 @@ public function __construct(ScopeFactoryInterface $scopeFactory = null)
7272
public function createData(
7373
ResourceInterface $resource,
7474
?string $scopeIdentifier = null,
75-
Scope $parentScopeInstance = null
75+
?Scope $parentScopeInstance = null
7676
): Scope {
7777
if ($parentScopeInstance !== null) {
7878
return $this->scopeFactory->createChildScopeFor($this, $parentScopeInstance, $resource, $scopeIdentifier);

src/Pagination/DoctrinePaginatorAdapter.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
*/
2020
class DoctrinePaginatorAdapter implements PaginatorInterface
2121
{
22+
use PaginatorCountTrait;
23+
2224
/**
2325
* The paginator instance.
2426
* @var Paginator
@@ -73,7 +75,7 @@ public function getTotal(): int
7375
*/
7476
public function getCount(): int
7577
{
76-
return $this->paginator->getIterator()->count();
78+
return $this->getTraversableCount($this->paginator->getIterator());
7779
}
7880

7981
/**
@@ -93,7 +95,7 @@ public function getUrl(int $page): string
9395
}
9496

9597
/**
96-
* Get the the route generator.
98+
* Get the route generator.
9799
*/
98100
private function getRouteGenerator(): callable
99101
{
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the League\Fractal package.
5+
*
6+
* (c) Phil Sturgeon <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace League\Fractal\Pagination;
13+
14+
use Laminas\Paginator\Paginator;
15+
16+
/**
17+
* A paginator adapter for laminas/laminas-paginator.
18+
*
19+
* @author Abdul Malik Ikhsan <[email protected]>
20+
*/
21+
class LaminasPaginatorAdapter implements PaginatorInterface
22+
{
23+
protected Paginator $paginator;
24+
25+
/**
26+
* The route generator.
27+
*
28+
* @var callable
29+
*/
30+
protected $routeGenerator;
31+
32+
public function __construct(Paginator $paginator, callable $routeGenerator)
33+
{
34+
$this->paginator = $paginator;
35+
$this->routeGenerator = $routeGenerator;
36+
}
37+
38+
/**
39+
* {@inheritDoc}
40+
*/
41+
public function getCurrentPage(): int
42+
{
43+
return $this->paginator->getCurrentPageNumber();
44+
}
45+
46+
/**
47+
* {@inheritDoc}
48+
*/
49+
public function getLastPage(): int
50+
{
51+
return $this->paginator->count();
52+
}
53+
54+
/**
55+
* {@inheritDoc}
56+
*/
57+
public function getTotal(): int
58+
{
59+
return $this->paginator->getTotalItemCount();
60+
}
61+
62+
/**
63+
* {@inheritDoc}
64+
*/
65+
public function getCount(): int
66+
{
67+
return $this->paginator->getCurrentItemCount();
68+
}
69+
70+
/**
71+
* {@inheritDoc}
72+
*/
73+
public function getPerPage(): int
74+
{
75+
return $this->paginator->getItemCountPerPage();
76+
}
77+
78+
/**
79+
* {@inheritDoc}
80+
*/
81+
public function getUrl(int $page): string
82+
{
83+
return call_user_func($this->routeGenerator, $page);
84+
}
85+
86+
public function getPaginator(): Paginator
87+
{
88+
return $this->paginator;
89+
}
90+
91+
public function getRouteGenerator(): callable
92+
{
93+
return $this->routeGenerator;
94+
}
95+
}

src/Pagination/PagerfantaPaginatorAdapter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
*/
2121
class PagerfantaPaginatorAdapter implements PaginatorInterface
2222
{
23+
use PaginatorCountTrait;
24+
2325
protected Pagerfanta $paginator;
2426

2527
/**
@@ -64,7 +66,7 @@ public function getTotal(): int
6466
*/
6567
public function getCount(): int
6668
{
67-
return count($this->paginator->getCurrentPageResults());
69+
return $this->getIterableCount($this->paginator->getCurrentPageResults());
6870
}
6971

7072
/**

0 commit comments

Comments
 (0)