Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-8470: Upgraded Pagerfanta to v3 for Symfony 6 #462

Merged
merged 27 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
aa31064
[Composer] Bumped pagerfanta/pagerfanta requirement to ^3.6.2
alongosz Nov 27, 2024
ae21105
[Pagerfanta] Aligned adapters with v3
alongosz Dec 3, 2024
b9ed573
[Pagerfanta] Aligned CopySubtreeCommand with totalCount changes and i…
alongosz Dec 3, 2024
7b700be
[Pagerfanta][PHPStan] Declared template on `Content\Search\SearchResult`
alongosz Dec 10, 2024
d81b0ca
[Pagerfanta] Aligned totalCount strict type hints (`int<0, max>`)
alongosz Dec 10, 2024
0c007ad
[Pagerfanta] Defined ContentViewQueryTypeMapper::map strict return type
alongosz Dec 10, 2024
484ca9f
[Pagerfanta][PHPStan] Defined TFilteringLanguageFilter for Filtering API
alongosz Dec 10, 2024
d9742fd
[Pagerfanta][PHPStan] Defined TSearchLanguageFilter for Search API
alongosz Dec 10, 2024
1dacbcc
[Pagerfanta] Aligned Core Pagerfanta implementation with Pagerfanta v3
alongosz Dec 10, 2024
e2897f4
[Pagerfanta][PHPStan] Implemented Pagerfanta v3 templates
alongosz Dec 10, 2024
0647976
[Pagerfanta] Fixed related classes' code quality and PHPDoc
alongosz Dec 10, 2024
ddf6dbe
[Pagerfanta] Fixed related implementation code quality
alongosz Dec 10, 2024
2641c05
[Pagerfanta][Tests] Refactored adapter tests to follow the changes
alongosz Dec 10, 2024
5041bef
[Pagerfanta][Tests] Improved code quality of related test classes
alongosz Dec 10, 2024
cc95071
[Pagerfanta][PHPStan] Created Pagerfanta baseline
alongosz Dec 10, 2024
fa21a6a
[Pagerfanta][PHPStan] Fixed incorrect persistence findLocations retur…
alongosz Dec 10, 2024
55ba1cf
[Pagerfanta][PHPStan] Fixed UserService::searchSubGroups return type
alongosz Dec 10, 2024
481fd02
[Pagerfanta]Fixed LSE Handler findContent & findLocation impl. type h…
alongosz Dec 10, 2024
4804d7a
[Pagerfanta] Improved type hints of QueryRenderController
alongosz Dec 11, 2024
44fb549
[Pagerfanta][Tests] Improved QueryRenderControllerTest
alongosz Dec 11, 2024
2b768e8
[Pagerfanta] Fixed incorrect return types of SearchHitAdapterFactory …
alongosz Dec 11, 2024
0a8ed88
[Pagerfanta][PHPStan] Removed resolved issues from the main baseline
alongosz Dec 11, 2024
7d97e72
[Pagerfanta][PHPStan] Aligned Pagerfanta baseline with resolved issues
alongosz Dec 11, 2024
014a41d
[Pagerfanta] Fixed LSE total count regression when there's no count t…
alongosz Dec 12, 2024
12d21ce
Changed infinity to tilde in CopySubtreeCommand
alongosz Dec 12, 2024
54ae413
Dropped leftover PHPDoc type hints from CopySubtreeCommand
alongosz Dec 12, 2024
17e2c05
[Tests][CS] Fixed CS in BaseContentSearchResultAdapterTestCase
alongosz Dec 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"liip/imagine-bundle": "^2.3",
"nelmio/cors-bundle": "^2.0",
"oneup/flysystem-bundle": "^4.4.2",
"pagerfanta/pagerfanta": "^2.1",
"pagerfanta/pagerfanta": "^3.6.2",
"psr/event-dispatcher": "^1.0",
"sensio/framework-extra-bundle": "^6.1",
"symfony-cmf/routing": "^3.0",
Expand Down
561 changes: 3 additions & 558 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

241 changes: 241 additions & 0 deletions phpstan-baseline.pagerfanta.neon

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-symfony/extension.neon
- phpstan-baseline.neon
- phpstan-baseline.pagerfanta.neon

parameters:
level: 8
Expand Down
39 changes: 13 additions & 26 deletions src/bundle/Core/Command/CopySubtreeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,15 @@ class CopySubtreeCommand extends Command

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

/** @var \Ibexa\Contracts\Core\Repository\LocationService */
private $locationService;
private LocationService $locationService;

/** @var \Ibexa\Contracts\Core\Repository\PermissionResolver */
private $permissionResolver;
private PermissionResolver $permissionResolver;

/** @var \Ibexa\Contracts\Core\Repository\UserService */
private $userService;
private UserService $userService;

/** @var \Ibexa\Contracts\Core\Repository\ContentTypeService */
private $contentTypeService;
private ContentTypeService $contentTypeService;

/** @var \Ibexa\Contracts\Core\Repository\SearchService */
private $searchService;
private SearchService $searchService;

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

protected function configure()
protected function configure(): void
{
$this
->addArgument(
Expand All @@ -95,9 +90,10 @@ protected function configure()
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
*/
protected function initialize(InputInterface $input, OutputInterface $output)
protected function initialize(InputInterface $input, OutputInterface $output): void
{
parent::initialize($input, $output);
$this->permissionResolver->setCurrentUserReference(
Expand All @@ -106,11 +102,6 @@ protected function initialize(InputInterface $input, OutputInterface $output)
}

/**
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
*
* @return int|null
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
* @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentException
Expand Down Expand Up @@ -144,9 +135,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$questionHelper = $this->getHelper('question');
$question = new ConfirmationQuestion(
sprintf(
'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]? ',
'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]? ',
$sourceLocation->contentInfo->name,
$this->getAllChildrenCount($sourceLocation),
$this->getAllChildrenCountExpr($sourceLocation),
$targetLocation->contentInfo->name
)
);
Expand All @@ -168,20 +159,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

/**
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Location $location
*
* @return int
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
protected function getAllChildrenCount(Location $location): int
protected function getAllChildrenCountExpr(Location $location): string
{
$query = new LocationQuery([
'filter' => new Criterion\Subtree($location->pathString),
]);

$searchResults = $this->searchService->findLocations($query);
$totalCount = $this->searchService->findLocations($query)->totalCount;

return $searchResults->totalCount;
return $totalCount !== null ? (string) $totalCount : '~';
}
}
7 changes: 2 additions & 5 deletions src/bundle/Core/Command/ResizeOriginalImagesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
while ($query->offset <= $totalCount) {
$results = $this->searchService->findContent($query);

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

/**
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit $hit
* @param string $imageFieldIdentifier
* @param string $filter
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit<\Ibexa\Contracts\Core\Repository\Values\Content\Content> $hit
*/
private function resize(OutputInterface $output, SearchHit $hit, string $imageFieldIdentifier, string $filter): void
{
Expand Down
15 changes: 8 additions & 7 deletions src/bundle/Core/Features/Context/UserContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,27 @@ public function searchUserByLogin($username, $parentGroupId = null)
* Search User Groups with given name.
*
* @param string $name name of User Group to search for
* @param string $parentLocationId (optional) parent location id to search in
* @param int|null $parentLocationId (optional) parent location id to search in
*
* @return \Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit[] search results
* @phpstan-return list<\Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit<\Ibexa\Contracts\Core\Repository\Values\Content\Content>>
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidCriterionArgumentException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
public function searchUserGroups($name, $parentLocationId = null)
public function searchUserGroups(string $name, ?int $parentLocationId = null): array
{
$criterionArray = [
new Criterion\Subtree(self::USERGROUP_ROOT_SUBTREE),
new Criterion\ContentTypeIdentifier(self::USERGROUP_CONTENT_IDENTIFIER),
new Criterion\Field('name', Criterion\Operator::EQ, $name),
];
if ($parentLocationId) {
if (null !== $parentLocationId) {
$criterionArray[] = new Criterion\ParentLocationId($parentLocationId);
}
$query = new Query();
$query->filter = new Criterion\LogicalAnd($criterionArray);

$result = $this->searchService->findContent($query, [], false);

return $result->searchHits;
return $this->searchService->findContent($query, [], false)->searchHits;
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/contracts/Repository/ContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

/**
* This class provides service methods for managing content.
*
* @phpstan-type TFilteringLanguageFilter array<int, string>
*/
interface ContentService
{
Expand Down Expand Up @@ -511,7 +513,7 @@ public function validate(ValueObject $object, array $context, ?array $fieldIdent
/**
* Fetches Content items from the Repository filtered by the given conditions.
*
* @param array<int, string> $languages A list of language codes to be added as additional constraints.
* @phpstan-param TFilteringLanguageFilter|null $languages A list of language codes to be added as additional constraints.
* If skipped, by default, unless SiteAccessAware layer has been disabled, languages set
* for a SiteAccess in a current context will be used.
*/
Expand All @@ -522,9 +524,11 @@ public function find(Filter $filter, ?array $languages = null): ContentList;
*
* Counts total number of items returned by {@see ContentService::find()} with the same parameters.
*
* @param array<int, string> $languages A list of language codes to be added as additional constraints.
* @phpstan-param TFilteringLanguageFilter|null $languages $languages A list of language codes to be added as additional constraints.
* If skipped, by default, unless SiteAccessAware layer has been disabled, languages set
* for a SiteAccess in a current context will be used.
*
* @phpstan-return int<0, max>
*/
public function count(Filter $filter, ?array $languages = null): int;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,26 @@
use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult;
use Iterator;

/**
* @template TSearchHitValueObject of \Ibexa\Contracts\Core\Repository\Values\ValueObject
*
* @phpstan-import-type TSearchLanguageFilter from \Ibexa\Contracts\Core\Repository\SearchService
*/
abstract class AbstractSearchAdapter implements BatchIteratorAdapter
{
/** @var \Ibexa\Contracts\Core\Repository\SearchService */
protected $searchService;
protected SearchService $searchService;

/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Query */
protected $query;
protected Query $query;

/** @var string[] */
protected $languageFilter;
/** @phpstan-var TSearchLanguageFilter */
protected array $languageFilter;

/** @var bool */
protected $filterOnUserPermissions;
protected bool $filterOnUserPermissions;

/**
* @phpstan-param TSearchLanguageFilter $languageFilter
*/
public function __construct(
SearchService $searchService,
Query $query,
Expand All @@ -49,5 +55,10 @@ final public function fetch(int $offset, int $limit): Iterator
return $this->executeSearch($query)->getIterator();
}

/**
* @phpstan-return \Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult<TSearchHitValueObject>
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
abstract protected function executeSearch(Query $query): SearchResult;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@
use Ibexa\Contracts\Core\Repository\Values\Content\Query;
use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult;

/**
* @extends \Ibexa\Contracts\Core\Repository\Iterator\BatchIteratorAdapter\AbstractSearchAdapter<\Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo>
*/
final class ContentInfoSearchAdapter extends AbstractSearchAdapter
{
/**
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
*/
protected function executeSearch(Query $query): SearchResult
{
return $this->searchService->findContentInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
use Ibexa\Contracts\Core\Repository\Values\Content\Query;
use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult;

/**
* @extends \Ibexa\Contracts\Core\Repository\Iterator\BatchIteratorAdapter\AbstractSearchAdapter<\Ibexa\Contracts\Core\Repository\Values\Content\Content>
*/
final class ContentSearchAdapter extends AbstractSearchAdapter
{
protected function executeSearch(Query $query): SearchResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@

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

use Ibexa\Contracts\Core\Exception\InvalidArgumentException;
use Ibexa\Contracts\Core\Repository\SearchService;
use Ibexa\Contracts\Core\Repository\Values\Content\LocationQuery;
use Ibexa\Contracts\Core\Repository\Values\Content\Query;
use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult;

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

protected function executeSearch(Query $query): SearchResult
{
if (!$query instanceof LocationQuery) {
throw new InvalidArgumentException(
'$query',
sprintf(
'Expected an instance of %s, got %s',
LocationQuery::class,
get_class($query)
)
);
}

return $this->searchService->findLocations(
$query,
$this->languageFilter,
Expand Down
6 changes: 4 additions & 2 deletions src/contracts/Repository/LocationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

/**
* Location service, used for complex subtree operations.
*
* @phpstan-type TFilteringLanguageFilter array<int, string>
*/
interface LocationService
{
Expand Down Expand Up @@ -260,7 +262,7 @@ public function loadAllLocations(int $offset = 0, int $limit = 25): array;
/**
* Fetch a LocationList from the Repository filtered by the given conditions.
*
* @param string[] $languages a list of language codes to be added as additional constraints.
* @phpstan-param TFilteringLanguageFilter|null $languages a list of language codes to be added as additional constraints.
* If skipped, by default, unless SiteAccessAware layer has been disabled, languages set
* for a SiteAccess in a current context will be used.
*/
Expand All @@ -269,7 +271,7 @@ public function find(Filter $filter, ?array $languages = null): LocationList;
/**
* Count total number of items returned by {@see find} method.
*
* @param string[] $languages a list of language codes to be added as additional constraints.
* @phpstan-param TFilteringLanguageFilter|null $languages a list of language codes to be added as additional constraints.
* If skipped, by default, unless SiteAccessAware layer has been disabled, languages set
* for a SiteAccess in a current context will be used.
*/
Expand Down
Loading
Loading