Skip to content

Commit d3cb362

Browse files
alongoszViniTou
andauthored
IBX-8470: Upgraded Pagerfanta to v3 for Symfony 6 (#462)
For the list of Pagerfanta changes see #462 --------- Co-Authored-By: Dawid Parafiński <[email protected]>
1 parent 6a25c07 commit d3cb362

File tree

53 files changed

+1241
-1202
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1241
-1202
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"liip/imagine-bundle": "^2.3",
3333
"nelmio/cors-bundle": "^2.0",
3434
"oneup/flysystem-bundle": "^4.4.2",
35-
"pagerfanta/pagerfanta": "^2.1",
35+
"pagerfanta/pagerfanta": "^3.6.2",
3636
"psr/event-dispatcher": "^1.0",
3737
"sensio/framework-extra-bundle": "^6.1",
3838
"symfony-cmf/routing": "^3.0",

phpstan-baseline.neon

Lines changed: 3 additions & 558 deletions
Large diffs are not rendered by default.

phpstan-baseline.pagerfanta.neon

Lines changed: 241 additions & 0 deletions
Large diffs are not rendered by default.

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ includes:
22
- vendor/phpstan/phpstan-phpunit/extension.neon
33
- vendor/phpstan/phpstan-symfony/extension.neon
44
- phpstan-baseline.neon
5+
- phpstan-baseline.pagerfanta.neon
56

67
parameters:
78
level: 8

src/bundle/Core/Command/CopySubtreeCommand.php

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,15 @@ class CopySubtreeCommand extends Command
3232

3333
protected static $defaultDescription = 'Copies a subtree from one Location to another';
3434

35-
/** @var \Ibexa\Contracts\Core\Repository\LocationService */
36-
private $locationService;
35+
private LocationService $locationService;
3736

38-
/** @var \Ibexa\Contracts\Core\Repository\PermissionResolver */
39-
private $permissionResolver;
37+
private PermissionResolver $permissionResolver;
4038

41-
/** @var \Ibexa\Contracts\Core\Repository\UserService */
42-
private $userService;
39+
private UserService $userService;
4340

44-
/** @var \Ibexa\Contracts\Core\Repository\ContentTypeService */
45-
private $contentTypeService;
41+
private ContentTypeService $contentTypeService;
4642

47-
/** @var \Ibexa\Contracts\Core\Repository\SearchService */
48-
private $searchService;
43+
private SearchService $searchService;
4944

5045
/**
5146
* @param \Ibexa\Contracts\Core\Repository\LocationService $locationService
@@ -69,7 +64,7 @@ public function __construct(
6964
$this->searchService = $searchService;
7065
}
7166

72-
protected function configure()
67+
protected function configure(): void
7368
{
7469
$this
7570
->addArgument(
@@ -95,9 +90,10 @@ protected function configure()
9590
* @param \Symfony\Component\Console\Input\InputInterface $input
9691
* @param \Symfony\Component\Console\Output\OutputInterface $output
9792
*
93+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
9894
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
9995
*/
100-
protected function initialize(InputInterface $input, OutputInterface $output)
96+
protected function initialize(InputInterface $input, OutputInterface $output): void
10197
{
10298
parent::initialize($input, $output);
10399
$this->permissionResolver->setCurrentUserReference(
@@ -106,11 +102,6 @@ protected function initialize(InputInterface $input, OutputInterface $output)
106102
}
107103

108104
/**
109-
* @param \Symfony\Component\Console\Input\InputInterface $input
110-
* @param \Symfony\Component\Console\Output\OutputInterface $output
111-
*
112-
* @return int|null
113-
*
114105
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
115106
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
116107
* @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentException
@@ -144,9 +135,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
144135
$questionHelper = $this->getHelper('question');
145136
$question = new ConfirmationQuestion(
146137
sprintf(
147-
'Are you sure you want to copy `%s` subtree (no. of children: %d) into `%s`? This may take a while for a big number of nested children [Y/n]? ',
138+
'Are you sure you want to copy `%s` subtree (no. of children: %s) into `%s`? This may take a while for a big number of nested children [Y/n]? ',
148139
$sourceLocation->contentInfo->name,
149-
$this->getAllChildrenCount($sourceLocation),
140+
$this->getAllChildrenCountExpr($sourceLocation),
150141
$targetLocation->contentInfo->name
151142
)
152143
);
@@ -168,20 +159,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
168159
}
169160

170161
/**
171-
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Location $location
172-
*
173-
* @return int
174-
*
175162
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
176163
*/
177-
protected function getAllChildrenCount(Location $location): int
164+
protected function getAllChildrenCountExpr(Location $location): string
178165
{
179166
$query = new LocationQuery([
180167
'filter' => new Criterion\Subtree($location->pathString),
181168
]);
182169

183-
$searchResults = $this->searchService->findLocations($query);
170+
$totalCount = $this->searchService->findLocations($query)->totalCount;
184171

185-
return $searchResults->totalCount;
172+
return $totalCount !== null ? (string) $totalCount : '~';
186173
}
187174
}

src/bundle/Core/Command/ResizeOriginalImagesCommand.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
210210
while ($query->offset <= $totalCount) {
211211
$results = $this->searchService->findContent($query);
212212

213-
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit $hit */
213+
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit<\Ibexa\Contracts\Core\Repository\Values\Content\Content> $hit */
214214
foreach ($results->searchHits as $hit) {
215215
$this->resize($output, $hit, $imageFieldIdentifier, $filter);
216216
$progressBar->advance();
@@ -232,10 +232,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
232232
}
233233

234234
/**
235-
* @param \Symfony\Component\Console\Output\OutputInterface $output
236-
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit $hit
237-
* @param string $imageFieldIdentifier
238-
* @param string $filter
235+
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit<\Ibexa\Contracts\Core\Repository\Values\Content\Content> $hit
239236
*/
240237
private function resize(OutputInterface $output, SearchHit $hit, string $imageFieldIdentifier, string $filter): void
241238
{

src/bundle/Core/Features/Context/UserContext.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,26 +82,27 @@ public function searchUserByLogin($username, $parentGroupId = null)
8282
* Search User Groups with given name.
8383
*
8484
* @param string $name name of User Group to search for
85-
* @param string $parentLocationId (optional) parent location id to search in
85+
* @param int|null $parentLocationId (optional) parent location id to search in
8686
*
87-
* @return \Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit[] search results
87+
* @phpstan-return list<\Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit<\Ibexa\Contracts\Core\Repository\Values\Content\Content>>
88+
*
89+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidCriterionArgumentException
90+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
8891
*/
89-
public function searchUserGroups($name, $parentLocationId = null)
92+
public function searchUserGroups(string $name, ?int $parentLocationId = null): array
9093
{
9194
$criterionArray = [
9295
new Criterion\Subtree(self::USERGROUP_ROOT_SUBTREE),
9396
new Criterion\ContentTypeIdentifier(self::USERGROUP_CONTENT_IDENTIFIER),
9497
new Criterion\Field('name', Criterion\Operator::EQ, $name),
9598
];
96-
if ($parentLocationId) {
99+
if (null !== $parentLocationId) {
97100
$criterionArray[] = new Criterion\ParentLocationId($parentLocationId);
98101
}
99102
$query = new Query();
100103
$query->filter = new Criterion\LogicalAnd($criterionArray);
101104

102-
$result = $this->searchService->findContent($query, [], false);
103-
104-
return $result->searchHits;
105+
return $this->searchService->findContent($query, [], false)->searchHits;
105106
}
106107

107108
/**

src/contracts/Repository/ContentService.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
/**
3030
* This class provides service methods for managing content.
31+
*
32+
* @phpstan-type TFilteringLanguageFilter array<int, string>
3133
*/
3234
interface ContentService
3335
{
@@ -511,7 +513,7 @@ public function validate(ValueObject $object, array $context, ?array $fieldIdent
511513
/**
512514
* Fetches Content items from the Repository filtered by the given conditions.
513515
*
514-
* @param array<int, string> $languages A list of language codes to be added as additional constraints.
516+
* @phpstan-param TFilteringLanguageFilter|null $languages A list of language codes to be added as additional constraints.
515517
* If skipped, by default, unless SiteAccessAware layer has been disabled, languages set
516518
* for a SiteAccess in a current context will be used.
517519
*/
@@ -522,9 +524,11 @@ public function find(Filter $filter, ?array $languages = null): ContentList;
522524
*
523525
* Counts total number of items returned by {@see ContentService::find()} with the same parameters.
524526
*
525-
* @param array<int, string> $languages A list of language codes to be added as additional constraints.
527+
* @phpstan-param TFilteringLanguageFilter|null $languages $languages A list of language codes to be added as additional constraints.
526528
* If skipped, by default, unless SiteAccessAware layer has been disabled, languages set
527529
* for a SiteAccess in a current context will be used.
530+
*
531+
* @phpstan-return int<0, max>
528532
*/
529533
public function count(Filter $filter, ?array $languages = null): int;
530534
}

src/contracts/Repository/Iterator/BatchIteratorAdapter/AbstractSearchAdapter.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,26 @@
1414
use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult;
1515
use Iterator;
1616

17+
/**
18+
* @template TSearchHitValueObject of \Ibexa\Contracts\Core\Repository\Values\ValueObject
19+
*
20+
* @phpstan-import-type TSearchLanguageFilter from \Ibexa\Contracts\Core\Repository\SearchService
21+
*/
1722
abstract class AbstractSearchAdapter implements BatchIteratorAdapter
1823
{
19-
/** @var \Ibexa\Contracts\Core\Repository\SearchService */
20-
protected $searchService;
24+
protected SearchService $searchService;
2125

22-
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Query */
23-
protected $query;
26+
protected Query $query;
2427

25-
/** @var string[] */
26-
protected $languageFilter;
28+
/** @phpstan-var TSearchLanguageFilter */
29+
protected array $languageFilter;
2730

2831
/** @var bool */
29-
protected $filterOnUserPermissions;
32+
protected bool $filterOnUserPermissions;
3033

34+
/**
35+
* @phpstan-param TSearchLanguageFilter $languageFilter
36+
*/
3137
public function __construct(
3238
SearchService $searchService,
3339
Query $query,
@@ -49,5 +55,10 @@ final public function fetch(int $offset, int $limit): Iterator
4955
return $this->executeSearch($query)->getIterator();
5056
}
5157

58+
/**
59+
* @phpstan-return \Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult<TSearchHitValueObject>
60+
*
61+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
62+
*/
5263
abstract protected function executeSearch(Query $query): SearchResult;
5364
}

src/contracts/Repository/Iterator/BatchIteratorAdapter/ContentInfoSearchAdapter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@
1111
use Ibexa\Contracts\Core\Repository\Values\Content\Query;
1212
use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult;
1313

14+
/**
15+
* @extends \Ibexa\Contracts\Core\Repository\Iterator\BatchIteratorAdapter\AbstractSearchAdapter<\Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo>
16+
*/
1417
final class ContentInfoSearchAdapter extends AbstractSearchAdapter
1518
{
19+
/**
20+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
21+
*/
1622
protected function executeSearch(Query $query): SearchResult
1723
{
1824
return $this->searchService->findContentInfo(

src/contracts/Repository/Iterator/BatchIteratorAdapter/ContentSearchAdapter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use Ibexa\Contracts\Core\Repository\Values\Content\Query;
1212
use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult;
1313

14+
/**
15+
* @extends \Ibexa\Contracts\Core\Repository\Iterator\BatchIteratorAdapter\AbstractSearchAdapter<\Ibexa\Contracts\Core\Repository\Values\Content\Content>
16+
*/
1417
final class ContentSearchAdapter extends AbstractSearchAdapter
1518
{
1619
protected function executeSearch(Query $query): SearchResult

src/contracts/Repository/Iterator/BatchIteratorAdapter/LocationSearchAdapter.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88

99
namespace Ibexa\Contracts\Core\Repository\Iterator\BatchIteratorAdapter;
1010

11+
use Ibexa\Contracts\Core\Exception\InvalidArgumentException;
1112
use Ibexa\Contracts\Core\Repository\SearchService;
1213
use Ibexa\Contracts\Core\Repository\Values\Content\LocationQuery;
1314
use Ibexa\Contracts\Core\Repository\Values\Content\Query;
1415
use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult;
1516

17+
/**
18+
* @extends \Ibexa\Contracts\Core\Repository\Iterator\BatchIteratorAdapter\AbstractSearchAdapter<\Ibexa\Contracts\Core\Repository\Values\Content\Location>
19+
*/
1620
final class LocationSearchAdapter extends AbstractSearchAdapter
1721
{
1822
public function __construct(
@@ -26,6 +30,17 @@ public function __construct(
2630

2731
protected function executeSearch(Query $query): SearchResult
2832
{
33+
if (!$query instanceof LocationQuery) {
34+
throw new InvalidArgumentException(
35+
'$query',
36+
sprintf(
37+
'Expected an instance of %s, got %s',
38+
LocationQuery::class,
39+
get_class($query)
40+
)
41+
);
42+
}
43+
2944
return $this->searchService->findLocations(
3045
$query,
3146
$this->languageFilter,

src/contracts/Repository/LocationService.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
/**
2020
* Location service, used for complex subtree operations.
21+
*
22+
* @phpstan-type TFilteringLanguageFilter array<int, string>
2123
*/
2224
interface LocationService
2325
{
@@ -260,7 +262,7 @@ public function loadAllLocations(int $offset = 0, int $limit = 25): array;
260262
/**
261263
* Fetch a LocationList from the Repository filtered by the given conditions.
262264
*
263-
* @param string[] $languages a list of language codes to be added as additional constraints.
265+
* @phpstan-param TFilteringLanguageFilter|null $languages a list of language codes to be added as additional constraints.
264266
* If skipped, by default, unless SiteAccessAware layer has been disabled, languages set
265267
* for a SiteAccess in a current context will be used.
266268
*/
@@ -269,7 +271,7 @@ public function find(Filter $filter, ?array $languages = null): LocationList;
269271
/**
270272
* Count total number of items returned by {@see find} method.
271273
*
272-
* @param string[] $languages a list of language codes to be added as additional constraints.
274+
* @phpstan-param TFilteringLanguageFilter|null $languages a list of language codes to be added as additional constraints.
273275
* If skipped, by default, unless SiteAccessAware layer has been disabled, languages set
274276
* for a SiteAccess in a current context will be used.
275277
*/

0 commit comments

Comments
 (0)